From 255fbfe97643db8447a902f696a0c096b4538a31 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Fri, 16 Feb 2024 05:47:53 +0100 Subject: [PATCH] adjustments --- internal/torrent/fixer.go | 2 +- internal/torrent/latestState.go | 5 +---- internal/torrent/manager.go | 2 +- internal/torrent/refresh.go | 14 +++++++++----- internal/torrent/types.go | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/torrent/fixer.go b/internal/torrent/fixer.go index 0b71283..4bc4b4c 100644 --- a/internal/torrent/fixer.go +++ b/internal/torrent/fixer.go @@ -22,7 +22,7 @@ func (t *TorrentManager) fixerAddCommand(trigger, command string) { } func (t *TorrentManager) processFixers(instances []realdebrid.Torrent) { - t.log.Debugf("Processing fixers (%d left)", t.fixers.Count()) + t.log.Debugf("Processing fixers (%d left: %v)", t.fixers.Count(), t.fixers) var toDelete []string var toRedownload []*Torrent allTorrents, _ := t.DirectoryMap.Get(INT_ALL) diff --git a/internal/torrent/latestState.go b/internal/torrent/latestState.go index 0098e01..74c28c9 100644 --- a/internal/torrent/latestState.go +++ b/internal/torrent/latestState.go @@ -11,10 +11,7 @@ func (ls *LibraryState) Eq(a LibraryState) bool { if ls.TotalCount == 0 || ls.FirstActiveTorrentId == "" || ls.FirstTorrentId == "" { return false } - if a.TotalCount != ls.TotalCount || a.ActiveCount != ls.ActiveCount || a.FirstActiveTorrentId != ls.FirstActiveTorrentId || a.FirstTorrentId != ls.FirstTorrentId { - return false - } - return true + return a.TotalCount == ls.TotalCount && a.ActiveCount == ls.ActiveCount && a.FirstActiveTorrentId == ls.FirstActiveTorrentId && a.FirstTorrentId == ls.FirstTorrentId } func (t *TorrentManager) setNewLatestState(checksum LibraryState) { diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index 83dda90..6c2b6b1 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -56,7 +56,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, w RemountTrigger: make(chan struct{}, 1), allAccessKeys: mapset.NewSet[string](), latestState: &LibraryState{}, - requiredVersion: "0.9.3-hotfix.4", + requiredVersion: "0.9.3-hotfix.10", workerPool: workerPool, log: log, } diff --git a/internal/torrent/refresh.go b/internal/torrent/refresh.go index 5d02b36..d893326 100644 --- a/internal/torrent/refresh.go +++ b/internal/torrent/refresh.go @@ -137,14 +137,16 @@ func (t *TorrentManager) StartRefreshJob() { // getMoreInfo gets original name, size and files for a torrent func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent { infoCache, _ := t.DirectoryMap.Get(INT_INFO_CACHE) + if torrentFromCache, exists := infoCache.Get(rdTorrent.ID); exists && !torrentFromCache.AnyInProgress() && torrentFromCache.SelectedFiles.Count() == len(rdTorrent.Links) { return torrentFromCache + } else if !exists { torrentFromFile := t.readTorrentFromFile(rdTorrent.ID) + if torrentFromFile != nil && - !torrentFromFile.AnyInProgress() && torrentFromFile.SelectedFiles.Count() == len(rdTorrent.Links) { hasBrokenFiles := false @@ -158,8 +160,7 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent { infoCache.Set(rdTorrent.ID, torrentFromFile) t.ResetSelectedFiles(torrentFromFile) return torrentFromFile - } else { - t.log.Warnf("Torrent %s has broken files, will not save on info cache", rdTorrent.ID) + } } } @@ -225,8 +226,11 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent { torrent.InProgressIDs.Add(info.ID) } - infoCache.Set(rdTorrent.ID, &torrent) - t.saveTorrentChangesToDisk(&torrent, nil) + // save to cache if it's not in progress anymore + if info.Progress == 100 { + infoCache.Set(rdTorrent.ID, &torrent) + t.saveTorrentChangesToDisk(&torrent, nil) + } return &torrent } diff --git a/internal/torrent/types.go b/internal/torrent/types.go index f4167a1..81d32e6 100644 --- a/internal/torrent/types.go +++ b/internal/torrent/types.go @@ -121,7 +121,7 @@ func (t *Torrent) AnyInProgress() bool { } func (t *Torrent) AllInProgress() bool { - return t.DownloadedIDs.IsEmpty() + return t.DownloadedIDs.IsEmpty() && !t.InProgressIDs.IsEmpty() } func (t *Torrent) ComputeTotalSize() int64 {