Optimizations

This commit is contained in:
Ben Sarmiento
2024-05-27 10:18:51 +02:00
parent 5c5a73e6e4
commit 4ec1c4496d
6 changed files with 76 additions and 75 deletions

View File

@@ -146,22 +146,19 @@ func (t *TorrentManager) repairAll(torrent *Torrent) {
}
func (t *TorrentManager) Repair(torrent *Torrent, wg *sync.WaitGroup) {
defer wg.Done()
// blocks for approx 45 minutes if active torrents are full
if !t.canCapacityHandle() {
t.repairLog.Error("Blocked for too long due to limit of active torrents, cannot continue with the repair")
wg.Done()
return
}
// assign to a worker
_ = t.workerPool.Submit(func() {
defer wg.Done()
if err := torrent.State.Event(context.Background(), "repair_torrent"); err != nil {
t.repairLog.Errorf("Failed to mark torrent %s as under repair: %v", t.GetKey(torrent), err)
return
}
t.repair(torrent)
})
if err := torrent.State.Event(context.Background(), "repair_torrent"); err != nil {
t.repairLog.Errorf("Failed to mark torrent %s as under repair: %v", t.GetKey(torrent), err)
return
}
t.repair(torrent)
}
// repairman
@@ -196,7 +193,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
// delete the torrents it replaced
torrent.DownloadedIDs.Each(func(torrentID string) bool {
if torrentID != info.ID {
t.setToBinOnceDone(fmt.Sprintf("%s-%s", info.ID, torrentID))
t.setXToBinOnceYDone(torrentID, info.ID)
}
return false
})
@@ -206,7 +203,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
// once info.ID is done, we can delete the old torrent
torrent.DownloadedIDs.Each(func(torrentID string) bool {
if torrentID != info.ID {
t.setToBinOnceDone(fmt.Sprintf("%s-%s", info.ID, torrentID))
t.setXToBinOnceYDone(torrentID, info.ID)
}
return false
})
@@ -441,8 +438,7 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection []string)
}
// documented status: magnet_error, magnet_conversion, waiting_files_selection, queued, downloading, downloaded, error, virus, compressing, uploading, dead
okStatuses := mapset.NewSet("downloading", "downloaded", "uploading", "queued", "compressing")
if !okStatuses.Contains(info.Status) {
if info.Status != "downloading" && info.Status != "downloaded" && info.Status != "uploading" && info.Status != "queued" && info.Status != "compressing" {
t.setToBinImmediately(newTorrentID)
return nil, fmt.Errorf("non-OK state: %s", info.Status)
}