fix subscription stale download dedup

This commit is contained in:
ShukeBta
2026-06-26 17:05:31 +08:00
parent 0e11d64a2f
commit a587054443
8 changed files with 235 additions and 6 deletions
+12 -4
View File
@@ -21,19 +21,27 @@ func (d *DownloadService) recordLiveTorrentSnapshot(live []QBitTorrent) {
}
func (d *DownloadService) LiveTorrentSnapshot(maxAge time.Duration) []QBitTorrent {
if d == nil {
snapshot, ok := d.liveTorrentSnapshot(maxAge)
if !ok {
return nil
}
return snapshot
}
func (d *DownloadService) liveTorrentSnapshot(maxAge time.Duration) ([]QBitTorrent, bool) {
if d == nil {
return nil, false
}
now := d.currentTime()
d.mu.Lock()
defer d.mu.Unlock()
if d.liveTorrentsAt.IsZero() {
return nil
return nil, false
}
if maxAge > 0 && now.Sub(d.liveTorrentsAt) > maxAge {
return nil
return nil, false
}
return cloneQBitTorrentSlice(d.liveTorrents)
return cloneQBitTorrentSlice(d.liveTorrents), true
}
func cloneQBitTorrentSlice(in []QBitTorrent) []QBitTorrent {