Refactor torrent fetching
This commit is contained in:
@@ -1,23 +1,21 @@
|
||||
package torrent
|
||||
|
||||
type LibraryState struct {
|
||||
TotalCount int
|
||||
ActiveCount int
|
||||
FirstActiveTorrentId string
|
||||
FirstTorrentId string
|
||||
TotalCount int
|
||||
ActiveCount int
|
||||
FirstTorrentId string
|
||||
}
|
||||
|
||||
func (ls *LibraryState) Eq(a LibraryState) bool {
|
||||
if ls.TotalCount == 0 || ls.FirstActiveTorrentId == "" || ls.FirstTorrentId == "" {
|
||||
if ls.TotalCount == 0 || ls.FirstTorrentId == "" {
|
||||
return false
|
||||
}
|
||||
return a.TotalCount == ls.TotalCount && a.ActiveCount == ls.ActiveCount && a.FirstActiveTorrentId == ls.FirstActiveTorrentId && a.FirstTorrentId == ls.FirstTorrentId
|
||||
return a.TotalCount == ls.TotalCount && a.ActiveCount == ls.ActiveCount && a.FirstTorrentId == ls.FirstTorrentId
|
||||
}
|
||||
|
||||
func (t *TorrentManager) setNewLatestState(checksum LibraryState) {
|
||||
t.latestState.ActiveCount = checksum.ActiveCount
|
||||
t.latestState.TotalCount = checksum.TotalCount
|
||||
t.latestState.FirstActiveTorrentId = checksum.FirstActiveTorrentId
|
||||
t.latestState.FirstTorrentId = checksum.FirstTorrentId
|
||||
}
|
||||
|
||||
@@ -25,16 +23,7 @@ func (t *TorrentManager) setNewLatestState(checksum LibraryState) {
|
||||
func (t *TorrentManager) getCurrentState() LibraryState {
|
||||
var state LibraryState
|
||||
|
||||
activeTorrents, _, err := t.Api.GetTorrents(1, true)
|
||||
if err != nil {
|
||||
t.log.Errorf("Checksum API Error (GetActiveTorrents): %v", err)
|
||||
return LibraryState{}
|
||||
}
|
||||
if len(activeTorrents) > 0 {
|
||||
state.FirstActiveTorrentId = activeTorrents[0].ID
|
||||
}
|
||||
|
||||
torrents, totalCount, err := t.Api.GetTorrents(1, true)
|
||||
torrents, totalCount, err := t.Api.GetTorrents(true)
|
||||
if err != nil {
|
||||
t.log.Errorf("Checksum API Error (GetTorrents): %v", err)
|
||||
return LibraryState{}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func (t *TorrentManager) refreshTorrents(isInitialRun bool) []string {
|
||||
instances, _, err := t.Api.GetTorrents(0, false)
|
||||
instances, _, err := t.Api.GetTorrents(false)
|
||||
if err != nil {
|
||||
t.log.Warnf("Cannot get torrents: %v", err)
|
||||
return nil
|
||||
|
||||
@@ -262,7 +262,7 @@ func (t *TorrentManager) repair(torrent *Torrent) {
|
||||
}
|
||||
|
||||
func (t *TorrentManager) assignUnassignedLinks(torrent *Torrent) bool {
|
||||
t.log.Infof("Trying to assign links to incomplete torrent %s", t.GetKey(torrent))
|
||||
t.log.Infof("Trying to assign %d links to incomplete torrent %s", torrent.UnassignedLinks.Cardinality(), t.GetKey(torrent))
|
||||
// handle torrents with incomplete links for selected files
|
||||
assignedCount := 0
|
||||
rarCount := 0
|
||||
@@ -272,8 +272,7 @@ func (t *TorrentManager) assignUnassignedLinks(torrent *Torrent) bool {
|
||||
unrestrict := t.UnrestrictLinkUntilOk(link)
|
||||
if unrestrict == nil {
|
||||
newUnassignedLinks.Set(link, nil)
|
||||
// return early, no point continuing
|
||||
return false
|
||||
return false // next
|
||||
}
|
||||
|
||||
// try to assign to a selected file
|
||||
|
||||
Reference in New Issue
Block a user