Optimize repair
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -375,7 +374,6 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
Added: info.Added,
|
Added: info.Added,
|
||||||
Ended: info.Ended,
|
Ended: info.Ended,
|
||||||
Link: "", // no link yet
|
Link: "", // no link yet
|
||||||
ZurgFS: hashStringToFh(file.Path + info.Hash),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if len(selectedFiles) > len(info.Links) && info.Progress == 100 {
|
if len(selectedFiles) > len(info.Links) && info.Progress == 100 {
|
||||||
@@ -404,12 +402,6 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
return &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 {
|
func (t *TorrentManager) getName(name, originalName string) string {
|
||||||
if t.cfg.EnableRetainRDTorrentName() {
|
if t.cfg.EnableRetainRDTorrentName() {
|
||||||
return name
|
return name
|
||||||
@@ -478,20 +470,15 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
link := link // redeclare to avoid closure on loop variable
|
link := link // redeclare to avoid closure on loop variable
|
||||||
// Use the existing worker pool to submit tasks
|
// Use the existing worker pool to submit tasks
|
||||||
err := t.antsPool.Submit(func() {
|
_ = t.antsPool.Submit(func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
resp := t.api.UnrestrictUntilOk(link)
|
resp := t.api.UnrestrictUntilOk(link)
|
||||||
resultsChan <- Result{Response: resp}
|
resultsChan <- Result{Response: resp}
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
t.log.Errorf("Error submitting task to worker pool: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
close(resultsChan)
|
close(resultsChan)
|
||||||
}()
|
|
||||||
|
|
||||||
isChaotic := false
|
isChaotic := false
|
||||||
for result := range resultsChan {
|
for result := range resultsChan {
|
||||||
@@ -518,7 +505,6 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([
|
|||||||
Added: now,
|
Added: now,
|
||||||
Ended: now,
|
Ended: now,
|
||||||
Link: result.Response.Link,
|
Link: result.Response.Link,
|
||||||
ZurgFS: hashStringToFh(result.Response.Filename),
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
isChaotic = true
|
isChaotic = true
|
||||||
@@ -609,7 +595,6 @@ func (t *TorrentManager) Repair(accessKey string) {
|
|||||||
Added: file.Added,
|
Added: file.Added,
|
||||||
Ended: file.Ended,
|
Ended: file.Ended,
|
||||||
Link: file.Link,
|
Link: file.Link,
|
||||||
ZurgFS: file.ZurgFS,
|
|
||||||
}
|
}
|
||||||
selectedFiles = append(selectedFiles, fileCopy)
|
selectedFiles = append(selectedFiles, fileCopy)
|
||||||
if strings.HasPrefix(fileCopy.Link, "http") {
|
if strings.HasPrefix(fileCopy.Link, "http") {
|
||||||
|
|||||||
@@ -37,5 +37,4 @@ type File struct {
|
|||||||
Added string
|
Added string
|
||||||
Ended string
|
Ended string
|
||||||
Link string
|
Link string
|
||||||
ZurgFS uint64
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user