Access key computation without clearing data
This commit is contained in:
@@ -44,13 +44,13 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
||||
continue
|
||||
}
|
||||
if !info.AnyInProgress() {
|
||||
freshKeys.Add(info.AccessKey)
|
||||
freshKeys.Add(t.GetKey(info))
|
||||
}
|
||||
if torrent, exists := allTorrents.Get(info.AccessKey); !exists {
|
||||
allTorrents.Set(info.AccessKey, info)
|
||||
if torrent, exists := allTorrents.Get(t.GetKey(info)); !exists {
|
||||
allTorrents.Set(t.GetKey(info), info)
|
||||
} else if !info.DownloadedIDs.Difference(torrent.DownloadedIDs).IsEmpty() {
|
||||
mainTorrent := t.mergeToMain(torrent, info)
|
||||
allTorrents.Set(info.AccessKey, &mainTorrent)
|
||||
allTorrents.Set(t.GetKey(info), &mainTorrent)
|
||||
}
|
||||
}
|
||||
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)
|
||||
@@ -130,9 +130,10 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
}
|
||||
|
||||
torrent := Torrent{
|
||||
AccessKey: t.computeAccessKey(info.Name, info.OriginalName),
|
||||
LatestAdded: info.Added,
|
||||
Hash: info.Hash,
|
||||
Name: info.Name,
|
||||
OriginalName: info.OriginalName,
|
||||
LatestAdded: info.Added,
|
||||
Hash: info.Hash,
|
||||
}
|
||||
// SelectedFiles is a subset of Files with only the selected ones
|
||||
// it also has a Link field, which can be empty
|
||||
@@ -180,21 +181,23 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
||||
torrent.InProgressIDs.Add(info.ID)
|
||||
}
|
||||
|
||||
t.writeTorrentToFile(rdTorrent.ID, &torrent)
|
||||
t.writeTorrentToFile(rdTorrent.ID, &torrent, true)
|
||||
infoCache.Set(rdTorrent.ID, &torrent)
|
||||
|
||||
return &torrent
|
||||
}
|
||||
|
||||
func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
||||
mainTorrent := Torrent{}
|
||||
|
||||
mainTorrent.AccessKey = existing.AccessKey
|
||||
mainTorrent.Hash = existing.Hash
|
||||
mainTorrent.DownloadedIDs = mapset.NewSet[string]()
|
||||
mainTorrent.InProgressIDs = mapset.NewSet[string]()
|
||||
mainTorrent.Unfixable = existing.Unfixable || toMerge.Unfixable
|
||||
mainTorrent.UnassignedLinks = existing.UnassignedLinks.Union(toMerge.UnassignedLinks)
|
||||
mainTorrent := Torrent{
|
||||
Name: existing.Name,
|
||||
OriginalName: existing.OriginalName,
|
||||
Rename: existing.Rename,
|
||||
Hash: existing.Hash,
|
||||
DownloadedIDs: mapset.NewSet[string](),
|
||||
InProgressIDs: mapset.NewSet[string](),
|
||||
Unfixable: existing.Unfixable || toMerge.Unfixable,
|
||||
UnassignedLinks: existing.UnassignedLinks.Union(toMerge.UnassignedLinks),
|
||||
}
|
||||
|
||||
// this function triggers only when we have a new DownloadedID
|
||||
toMerge.DownloadedIDs.Difference(existing.DownloadedIDs).Each(func(id string) bool {
|
||||
|
||||
Reference in New Issue
Block a user