More efficient repairs
This commit is contained in:
@@ -97,6 +97,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.RefreshTorrents()
|
t.RefreshTorrents()
|
||||||
|
|
||||||
if t.Config.EnableRepair() {
|
if t.Config.EnableRepair() {
|
||||||
repairWorker, err := ants.NewPool(1)
|
repairWorker, err := ants.NewPool(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -168,7 +169,6 @@ func (t *TorrentManager) RefreshTorrents() {
|
|||||||
t.accessKeySet.Add(accessKey)
|
t.accessKeySet.Add(accessKey)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
t.checkForOtherDeletedTorrents()
|
|
||||||
// now we can build the directory responses
|
// now we can build the directory responses
|
||||||
t.UpdateDirectoryResponsesCache()
|
t.UpdateDirectoryResponsesCache()
|
||||||
|
|
||||||
@@ -537,7 +537,7 @@ func (t *TorrentManager) repairAll() {
|
|||||||
}
|
}
|
||||||
forRepair := false
|
forRepair := false
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
if file.Link == "repair" && !forRepair {
|
if file.Link == "repair" {
|
||||||
file.Link = "repairing"
|
file.Link = "repairing"
|
||||||
forRepair = true
|
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 {
|
func (t *TorrentManager) CheckDeletedState(torrent *Torrent) bool {
|
||||||
var unselectedIDs []int
|
var unselectedIDs []int
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
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) {
|
func (t *TorrentManager) UpdateTorrentResponseCache(torrent *Torrent) {
|
||||||
dav, html := t.buildTorrentResponses(torrent)
|
dav, html := t.buildTorrentResponses(torrent)
|
||||||
t.AssignedDirectoryCb(torrent, func(directory string) {
|
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)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ func (gf *GetFile) HandleGetRequest(directory, torrentName, fileName string, res
|
|||||||
// log.Warnf("File %s is no longer available, link %s", filepath.Base(file.Path), link)
|
// log.Warnf("File %s is no longer available, link %s", filepath.Base(file.Path), link)
|
||||||
file.Link = "repairing"
|
file.Link = "repairing"
|
||||||
torMgr.Repair(torrent)
|
torMgr.Repair(torrent)
|
||||||
torMgr.UpdateTorrentResponseCache(torrent)
|
|
||||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -151,7 +150,6 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
|
|||||||
log.Warnf("Cannot download file %s: %v", file.Path, err)
|
log.Warnf("Cannot download file %s: %v", file.Path, err)
|
||||||
file.Link = "repairing"
|
file.Link = "repairing"
|
||||||
torMgr.Repair(torrent)
|
torMgr.Repair(torrent)
|
||||||
torMgr.UpdateTorrentResponseCache(torrent)
|
|
||||||
}
|
}
|
||||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
@@ -163,7 +161,6 @@ func (gf *GetFile) streamFileToResponse(torrent *intTor.Torrent, file *intTor.Fi
|
|||||||
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
|
log.Warnf("Received a %s status code for file %s", download.Status, file.Path)
|
||||||
file.Link = "repairing"
|
file.Link = "repairing"
|
||||||
torMgr.Repair(torrent)
|
torMgr.Repair(torrent)
|
||||||
torMgr.UpdateTorrentResponseCache(torrent)
|
|
||||||
}
|
}
|
||||||
http.Error(resp, "File is not available", http.StatusNotFound)
|
http.Error(resp, "File is not available", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user