From a7623de410fd567823de6b680e232e4d1c115490 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Sun, 26 Nov 2023 19:00:01 +0100 Subject: [PATCH] Optimize repair --- internal/torrent/manager.go | 43 ++++++++++++------------------------- internal/torrent/types.go | 7 +++--- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/internal/torrent/manager.go b/internal/torrent/manager.go index d948348..f5b0904 100644 --- a/internal/torrent/manager.go +++ b/internal/torrent/manager.go @@ -4,7 +4,6 @@ import ( "bufio" "encoding/gob" "fmt" - "hash/fnv" "math" "os" "path/filepath" @@ -371,11 +370,10 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent { continue } selectedFiles = append(selectedFiles, &File{ - File: file, - Added: info.Added, - Ended: info.Ended, - Link: "", // no link yet - ZurgFS: hashStringToFh(file.Path + info.Hash), + File: file, + Added: info.Added, + Ended: info.Ended, + Link: "", // no link yet }) } if len(selectedFiles) > len(info.Links) && info.Progress == 100 { @@ -404,12 +402,6 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent { return &torrent } -func hashStringToFh(s string) (fh uint64) { - hasher := fnv.New64a() - _, _ = hasher.Write([]byte(s)) // Write the string to the hasher; ignoring error as it never returns an error - return hasher.Sum64() // Returns a 64-bit hash value -} - func (t *TorrentManager) getName(name, originalName string) string { if t.cfg.EnableRetainRDTorrentName() { return name @@ -478,20 +470,15 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([ wg.Add(1) link := link // redeclare to avoid closure on loop variable // Use the existing worker pool to submit tasks - err := t.antsPool.Submit(func() { + _ = t.antsPool.Submit(func() { defer wg.Done() resp := t.api.UnrestrictUntilOk(link) resultsChan <- Result{Response: resp} }) - if err != nil { - t.log.Errorf("Error submitting task to worker pool: %v", err) - } } - go func() { - wg.Wait() - close(resultsChan) - }() + wg.Wait() + close(resultsChan) isChaotic := false for result := range resultsChan { @@ -515,10 +502,9 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([ Bytes: result.Response.Filesize, Selected: 1, }, - Added: now, - Ended: now, - Link: result.Response.Link, - ZurgFS: hashStringToFh(result.Response.Filename), + Added: now, + Ended: now, + Link: result.Response.Link, }) } else { isChaotic = true @@ -605,11 +591,10 @@ func (t *TorrentManager) Repair(accessKey string) { streamableCount++ } fileCopy := &File{ - File: file.File, - Added: file.Added, - Ended: file.Ended, - Link: file.Link, - ZurgFS: file.ZurgFS, + File: file.File, + Added: file.Added, + Ended: file.Ended, + Link: file.Link, } selectedFiles = append(selectedFiles, fileCopy) if strings.HasPrefix(fileCopy.Link, "http") { diff --git a/internal/torrent/types.go b/internal/torrent/types.go index fab0470..7f35343 100644 --- a/internal/torrent/types.go +++ b/internal/torrent/types.go @@ -34,8 +34,7 @@ func (t *Torrent) AllInProgress() bool { type File struct { realdebrid.File - Added string - Ended string - Link string - ZurgFS uint64 + Added string + Ended string + Link string }