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