Optimize repair

This commit is contained in:
Ben Sarmiento
2023-11-26 19:00:01 +01:00
parent 7a56bbcea0
commit a7623de410
2 changed files with 17 additions and 33 deletions

View File

@@ -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") {

View File

@@ -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
}