Immediate cleanup to prevent inconsistencies

This commit is contained in:
Ben Sarmiento
2024-05-28 03:51:01 +02:00
parent 2504b31d4c
commit 7470629486
5 changed files with 34 additions and 5 deletions

View File

@@ -15,6 +15,7 @@ import (
const ( const (
ALL_TORRENTS = "__all__" ALL_TORRENTS = "__all__"
UNPLAYABLE_TORRENTS = "__unplayable__" UNPLAYABLE_TORRENTS = "__unplayable__"
DUMPED_TORRENTS = "__dump__"
DOWNLOADS = "__downloads__" DOWNLOADS = "__downloads__"
) )
@@ -42,7 +43,7 @@ func (z *ZurgConfigV1) GetVersion() string {
} }
func (z *ZurgConfigV1) GetDirectories() []string { func (z *ZurgConfigV1) GetDirectories() []string {
rootDirectories := make([]string, len(z.Directories)+2) rootDirectories := make([]string, len(z.Directories)+3)
i := 0 i := 0
for directory := range z.Directories { for directory := range z.Directories {
rootDirectories[i] = directory rootDirectories[i] = directory
@@ -50,6 +51,7 @@ func (z *ZurgConfigV1) GetDirectories() []string {
} }
rootDirectories[i] = ALL_TORRENTS rootDirectories[i] = ALL_TORRENTS
rootDirectories[i+1] = UNPLAYABLE_TORRENTS rootDirectories[i+1] = UNPLAYABLE_TORRENTS
rootDirectories[i+2] = DUMPED_TORRENTS
return rootDirectories return rootDirectories
} }

19
internal/torrent/dump.go Normal file
View File

@@ -0,0 +1,19 @@
package torrent
import "github.com/debridmediamanager/zurg/internal/config"
func (t *TorrentManager) loadDumpedTorrents() {
// TODO: Paywall
count := 0
t.getTorrentFiles("data").Each(func(filePath string) bool {
torrent := t.readTorrentFromFile(filePath)
if torrent != nil {
accessKey := t.GetKey(torrent)
torrents, _ := t.DirectoryMap.Get(config.DUMPED_TORRENTS)
torrents.Set(accessKey, torrent)
count++
}
return false
})
t.log.Infof("Loaded %d dumped torrents", count)
}

View File

@@ -91,8 +91,12 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, r
t.initializeDirectoryMaps() t.initializeDirectoryMaps()
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(3)
t.workerPool.Submit(func() {
defer wg.Done()
t.loadDumpedTorrents()
})
t.workerPool.Submit(func() { t.workerPool.Submit(func() {
defer wg.Done() defer wg.Done()
@@ -417,8 +421,10 @@ func (t *TorrentManager) StartDumpJob() {
select { select {
case <-dumpTicker.C: case <-dumpTicker.C:
t.dumpTorrents() t.dumpTorrents()
t.loadDumpedTorrents()
case <-t.DumpTrigger: case <-t.DumpTrigger:
t.dumpTorrents() t.dumpTorrents()
t.loadDumpedTorrents()
} }
} }
}) })

View File

@@ -79,6 +79,10 @@ func (t *TorrentManager) refreshTorrents() []string {
}) })
} }
t.workerPool.Submit(func() {
t.cleanupBins(freshIDs)
})
wg.Wait() wg.Wait()
close(mergeChan) close(mergeChan)
@@ -136,8 +140,6 @@ func (t *TorrentManager) refreshTorrents() []string {
} }
return false return false
}) })
t.cleanupBins(freshIDs)
}) })
return updatedPaths.ToSlice() return updatedPaths.ToSlice()

View File

@@ -175,7 +175,7 @@ func (rd *RealDebrid) GetTorrents(onlyOne bool) ([]Torrent, int, error) {
// compute ceiling of totalCount / limit // compute ceiling of totalCount / limit
maxPages := (totalCount + rd.cfg.GetTorrentsCount() - 1) / rd.cfg.GetTorrentsCount() maxPages := (totalCount + rd.cfg.GetTorrentsCount() - 1) / rd.cfg.GetTorrentsCount()
rd.log.Debugf("Torrents total count is %d, max pages is %d", totalCount, maxPages) rd.log.Debugf("Torrents total count is %d, max pages is %d", totalCount, maxPages)
maxParallelThreads := 4 maxParallelThreads := 2
if maxPages < maxParallelThreads { if maxPages < maxParallelThreads {
maxParallelThreads = maxPages maxParallelThreads = maxPages
} }