Handle adds and deletes

This commit is contained in:
Ben Sarmiento
2023-12-06 02:02:01 +01:00
parent 4b8fd82acd
commit 0e471ba42d
5 changed files with 41 additions and 28 deletions

View File

@@ -131,7 +131,7 @@ func (t *TorrentManager) RefreshTorrents() {
t.log.Infof("Fetched info for %d torrents", len(instances))
freshKeys := set.NewStringSet()
oldTorrents, _ := t.DirectoryMap.Get(INT_ALL)
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
noInfoCount := 0
for info := range infoChan {
if info == nil {
@@ -139,14 +139,14 @@ func (t *TorrentManager) RefreshTorrents() {
continue
}
freshKeys.Add(info.AccessKey)
if torrent, exists := oldTorrents.Get(info.AccessKey); !exists {
oldTorrents.Set(info.AccessKey, info)
if torrent, exists := allTorrents.Get(info.AccessKey); !exists {
allTorrents.Set(info.AccessKey, info)
} else if !strset.Difference(info.DownloadedIDs, torrent.DownloadedIDs).IsEmpty() {
mainTorrent := t.mergeToMain(torrent, info)
oldTorrents.Set(info.AccessKey, &mainTorrent)
allTorrents.Set(info.AccessKey, &mainTorrent)
}
}
t.log.Infof("Compiled into %d torrents, %d were missing info", oldTorrents.Count(), noInfoCount)
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)
// removed
strset.Difference(t.accessKeySet, freshKeys).Each(func(accessKey string) bool {
@@ -156,6 +156,11 @@ func (t *TorrentManager) RefreshTorrents() {
// new
strset.Difference(freshKeys, t.accessKeySet).Each(func(accessKey string) bool {
t.accessKeySet.Add(accessKey)
tor, _ := allTorrents.Get(accessKey)
t.AssignedDirectoryCb(tor, func(directory string) {
torrents, _ := t.DirectoryMap.Get(directory)
torrents.Set(accessKey, tor)
})
return true
})