From d1b4158c96e0f0262466c0089cd3e4606d95f25b Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Wed, 7 Feb 2024 11:23:53 +0100 Subject: [PATCH] Merge even if in progress --- internal/torrent/refresh.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index 2bf1605..26ca77a 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -45,13 +45,18 @@ func (t *TorrentManager) refreshTorrents(isInitialRun bool) []string { continue } accessKey := t.GetKey(info) - if !info.AnyInProgress() { + if !info.AnyInProgress() { // since it's single instance info, Any == All newlyFetchedKeys.Add(accessKey) } - if torrent, exists := allTorrents.Get(accessKey); !exists { + torrent, exists := allTorrents.Get(accessKey) + if !exists { allTorrents.Set(accessKey, info) - } else if !info.DownloadedIDs.Difference(torrent.DownloadedIDs).IsEmpty() { + continue + } + newIDs := info.DownloadedIDs.Union(info.InProgressIDs) + oldIDs := torrent.DownloadedIDs.Union(torrent.InProgressIDs) + if !newIDs.Difference(oldIDs).IsEmpty() { mainTorrent := t.mergeToMain(torrent, info) allTorrents.Set(accessKey, &mainTorrent) }