Optimizations

This commit is contained in:
Ben Sarmiento
2023-11-18 18:11:28 +01:00
parent c520b5572f
commit 44ec4a0b00
3 changed files with 10 additions and 20 deletions

View File

@@ -260,13 +260,13 @@ func (t *TorrentManager) startRefreshJob() {
noInfoCount := 0
allTorrents, _ := t.DirectoryMap.Get("__all__")
var retain []string
retain := make(map[string]bool)
for info := range torrentsChan {
if info == nil {
noInfoCount++
continue
}
retain = append(retain, info.AccessKey)
retain[info.AccessKey] = true
if torrent, exists := allTorrents.Get(info.AccessKey); exists {
mainTorrent := t.mergeToMain(torrent, info)
allTorrents.Set(info.AccessKey, mainTorrent)
@@ -305,25 +305,12 @@ func (t *TorrentManager) startRefreshJob() {
})
// delete torrents that no longer exist
var toDelete []string
allTorrents.IterCb(func(_ string, torrent *Torrent) {
found := false
for _, accessKey := range retain {
if torrent.AccessKey == accessKey {
found = true
break
}
accessKeys := allTorrents.Keys()
for _, oldAccessKey := range accessKeys {
if _, ok := retain[oldAccessKey]; !ok {
allTorrents.Remove(oldAccessKey)
}
if !found {
toDelete = append(toDelete, torrent.AccessKey)
}
})
for _, accessKey := range toDelete {
t.DirectoryMap.IterCb(func(_ string, torrents cmap.ConcurrentMap[string, *Torrent]) {
torrents.Remove(accessKey)
})
}
// end delete torrents that no longer exist
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)