Single worker pool, client adjustments
This commit is contained in:
@@ -36,7 +36,6 @@ type TorrentManager struct {
|
||||
latestState *LibraryState
|
||||
requiredVersion string
|
||||
workerPool *ants.Pool
|
||||
unrestrictPool *ants.Pool
|
||||
log *zap.SugaredLogger
|
||||
}
|
||||
|
||||
@@ -57,14 +56,6 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
log: log,
|
||||
}
|
||||
|
||||
// create unrestrict pool
|
||||
unrestrictPool, err := ants.NewPool(t.Config.GetUnrestrictWorkers())
|
||||
if err != nil {
|
||||
t.unrestrictPool = t.workerPool
|
||||
} else {
|
||||
t.unrestrictPool = unrestrictPool
|
||||
}
|
||||
|
||||
// create internal directories
|
||||
t.DirectoryMap.Set(INT_ALL, cmap.New[*Torrent]()) // key is AccessKey
|
||||
t.DirectoryMap.Set(INT_INFO_CACHE, cmap.New[*Torrent]()) // key is Torrent ID
|
||||
@@ -92,6 +83,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
||||
})
|
||||
|
||||
var newTorrents []realdebrid.Torrent
|
||||
var err error
|
||||
initWait.Add(1)
|
||||
_ = t.workerPool.Submit(func() {
|
||||
defer initWait.Done()
|
||||
@@ -212,9 +204,8 @@ func (t *TorrentManager) mergeToMain(mainTorrent, torrentToMerge *Torrent) *Torr
|
||||
// proxy
|
||||
func (t *TorrentManager) UnrestrictUntilOk(link string) *realdebrid.Download {
|
||||
retChan := make(chan *realdebrid.Download, 1)
|
||||
t.unrestrictPool.Submit(func() {
|
||||
t.workerPool.Submit(func() {
|
||||
retChan <- t.Api.UnrestrictUntilOk(link, t.Config.ShouldServeFromRclone())
|
||||
time.Sleep(time.Duration(t.Config.GetReleaseUnrestrictAfterMs()) * time.Millisecond)
|
||||
})
|
||||
defer close(retChan)
|
||||
return <-retChan
|
||||
@@ -551,7 +542,7 @@ 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
|
||||
_ = t.unrestrictPool.Submit(func() {
|
||||
_ = t.workerPool.Submit(func() {
|
||||
defer wg.Done()
|
||||
if t.DownloadCache.Has(link) {
|
||||
download, _ := t.DownloadCache.Get(link)
|
||||
@@ -560,7 +551,6 @@ func (t *TorrentManager) organizeChaos(links []string, selectedFiles []*File) ([
|
||||
}
|
||||
resp := t.Api.UnrestrictUntilOk(link, t.Config.ShouldServeFromRclone())
|
||||
resultsChan <- Result{Response: resp}
|
||||
time.Sleep(time.Duration(t.Config.GetReleaseUnrestrictAfterMs()) * time.Millisecond)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user