separate thread for torrent list
This commit is contained in:
5
main.go
5
main.go
@@ -273,12 +273,15 @@ func main() {
|
|||||||
|
|
||||||
case "torrentListRequest":
|
case "torrentListRequest":
|
||||||
Logger.WithFields(logrus.Fields{"message": msg}).Debug("Client Requested TorrentList Update")
|
Logger.WithFields(logrus.Fields{"message": msg}).Debug("Client Requested TorrentList Update")
|
||||||
|
|
||||||
|
go func() { //running updates in separate thread so can still accept commands
|
||||||
TorrentLocalArray = Storage.FetchAllStoredTorrents(db) //Required to re-read th database since we write to the DB and this will pull the changes from it
|
TorrentLocalArray = Storage.FetchAllStoredTorrents(db) //Required to re-read th database since we write to the DB and this will pull the changes from it
|
||||||
RunningTorrentArray = Engine.CreateRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) //Updates the RunningTorrentArray with the current client data as well
|
RunningTorrentArray = Engine.CreateRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) //Updates the RunningTorrentArray with the current client data as well
|
||||||
PreviousTorrentArray = RunningTorrentArray
|
PreviousTorrentArray = RunningTorrentArray
|
||||||
torrentlistArray := Engine.TorrentList{MessageType: "torrentList", ClientDBstruct: RunningTorrentArray, Totaltorrents: len(RunningTorrentArray)}
|
torrentlistArray := Engine.TorrentList{MessageType: "torrentList", ClientDBstruct: RunningTorrentArray, Totaltorrents: len(RunningTorrentArray)}
|
||||||
Logger.WithFields(logrus.Fields{"torrentList": torrentlistArray, "previousTorrentList": PreviousTorrentArray}).Debug("Previous and Current Torrent Lists for sending to client")
|
Logger.WithFields(logrus.Fields{"torrentList": torrentlistArray, "previousTorrentList": PreviousTorrentArray}).Debug("Previous and Current Torrent Lists for sending to client")
|
||||||
conn.WriteJSON(torrentlistArray)
|
conn.WriteJSON(torrentlistArray)
|
||||||
|
}()
|
||||||
|
|
||||||
case "torrentFileListRequest": //client requested a filelist update
|
case "torrentFileListRequest": //client requested a filelist update
|
||||||
Logger.WithFields(logrus.Fields{"message": msg}).Debug("Client Requested FileList Update")
|
Logger.WithFields(logrus.Fields{"message": msg}).Debug("Client Requested FileList Update")
|
||||||
@@ -292,7 +295,7 @@ func main() {
|
|||||||
torrentPeerList := Engine.CreatePeerListArray(tclient, peerListArrayRequest)
|
torrentPeerList := Engine.CreatePeerListArray(tclient, peerListArrayRequest)
|
||||||
conn.WriteJSON(torrentPeerList)
|
conn.WriteJSON(torrentPeerList)
|
||||||
|
|
||||||
case "fetchTorrentsByLabel": //TODO test this to make sure it works
|
case "fetchTorrentsByLabel":
|
||||||
Logger.WithFields(logrus.Fields{"message": msg}).Debug("Client Requested Torrents by Label")
|
Logger.WithFields(logrus.Fields{"message": msg}).Debug("Client Requested Torrents by Label")
|
||||||
label := payloadData["Label"].(string)
|
label := payloadData["Label"].(string)
|
||||||
torrentsByLabel := Storage.FetchTorrentsByLabel(db, label)
|
torrentsByLabel := Storage.FetchTorrentsByLabel(db, label)
|
||||||
|
Reference in New Issue
Block a user