More efficient repairs

This commit is contained in:
Ben Sarmiento
2023-12-02 05:46:27 +01:00
parent 01a0da46e8
commit bba4418b8c
2 changed files with 19 additions and 34 deletions

View File

@@ -97,6 +97,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
}
t.RefreshTorrents()
if t.Config.EnableRepair() {
repairWorker, err := ants.NewPool(1)
if err != nil {
@@ -168,7 +169,6 @@ func (t *TorrentManager) RefreshTorrents() {
t.accessKeySet.Add(accessKey)
return true
})
t.checkForOtherDeletedTorrents()
// now we can build the directory responses
t.UpdateDirectoryResponsesCache()
@@ -537,7 +537,7 @@ func (t *TorrentManager) repairAll() {
}
forRepair := false
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
if file.Link == "repair" && !forRepair {
if file.Link == "repair" {
file.Link = "repairing"
forRepair = true
}
@@ -553,19 +553,6 @@ func (t *TorrentManager) repairAll() {
}
}
func (t *TorrentManager) checkForOtherDeletedTorrents() {
var toDelete []string
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
allTorrents.IterCb(func(_ string, torrent *Torrent) {
if t.CheckDeletedState(torrent) {
toDelete = append(toDelete, torrent.AccessKey)
}
})
for _, accessKey := range toDelete {
t.Delete(accessKey, true, false)
}
}
func (t *TorrentManager) CheckDeletedState(torrent *Torrent) bool {
var unselectedIDs []int
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
@@ -818,6 +805,23 @@ func (t *TorrentManager) canCapacityHandle() bool {
}
}
func (t *TorrentManager) RepairAll() {
_ = t.repairWorker.Submit(func() {
t.log.Info("Checking for torrents to repair")
t.repairAll()
t.log.Info("Finished checking for torrents to repair")
})
}
func (t *TorrentManager) Repair(torrent *Torrent) {
_ = t.repairWorker.Submit(func() {
t.log.Info("repairing torrent %s", torrent.AccessKey)
t.repair(torrent)
t.log.Info("Finished repairing torrent %s", torrent.AccessKey)
})
t.UpdateTorrentResponseCache(torrent)
}
func (t *TorrentManager) UpdateTorrentResponseCache(torrent *Torrent) {
dav, html := t.buildTorrentResponses(torrent)
t.AssignedDirectoryCb(torrent, func(directory string) {
@@ -900,19 +904,3 @@ func (t *TorrentManager) AssignedDirectoryCb(tor *Torrent, cb func(string)) {
}
}
}
func (t *TorrentManager) RepairAll() {
_ = t.repairWorker.Submit(func() {
t.log.Info("Checking for torrents to repair")
t.repairAll()
t.log.Info("Finished checking for torrents to repair")
})
}
func (t *TorrentManager) Repair(torrent *Torrent) {
_ = t.repairWorker.Submit(func() {
t.log.Info("repairing torrent %s", torrent.AccessKey)
t.repair(torrent)
t.log.Info("Finished repairing torrent %s", torrent.AccessKey)
})
}