Pop instead of just iterating

This commit is contained in:
Ben Sarmiento
2024-01-29 02:02:15 +01:00
parent 901bfdb1a6
commit 2a509f96ab

View File

@@ -27,7 +27,7 @@ func (t *TorrentManager) refreshTorrents() []string {
doesNotExist := t.deleteOnceDone.Clone()
for i := range instances {
idx := i
doesNotExist.Remove(instances[idx].ID)
doesNotExist.Remove(instances[idx].ID) // remove if existing
wg.Add(1)
_ = t.workerPool.Submit(func() {
defer wg.Done()
@@ -55,19 +55,23 @@ func (t *TorrentManager) refreshTorrents() []string {
return false
})
t.log.Debugf("Fixers left: %d", t.fixers.Count())
// ensure delete
infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE)
t.deleteOnceDone.Each(func(fixerID string) bool {
torrent, exists := infoCache.Get(fixerID)
if exists && torrent.AnyInProgress() {
return false
for {
fixerToDel, ok := t.deleteOnceDone.Pop()
if !ok {
break
}
t.log.Debugf("Ensuring that torrent id=%s is deleted", fixerID)
torrent, exists := infoCache.Get(fixerToDel)
if exists && torrent.AnyInProgress() {
continue
}
t.log.Debugf("Ensuring that torrent id=%s is deleted", fixerToDel)
t.Delete(t.GetKey(torrent), true)
t.Api.DeleteTorrent(fixerID)
infoCache.Remove(fixerID)
return false
})
t.Api.DeleteTorrent(fixerToDel)
infoCache.Remove(fixerToDel)
}
t.log.Debugf("Delete once done left: %d", t.deleteOnceDone.Cardinality())
newlyFetchedKeys := mapset.NewSet[string]()