Optimizations
This commit is contained in:
@@ -112,6 +112,9 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) ([]byte,
|
||||
sort.Strings(filenames)
|
||||
for _, filename := range filenames {
|
||||
file, _ := tor.SelectedFiles.Get(filename)
|
||||
if file == nil || file.Link == "" {
|
||||
continue
|
||||
}
|
||||
responses = append(responses, dav.File(
|
||||
filepath.Join(requestPath, filename),
|
||||
file.Bytes,
|
||||
|
||||
@@ -96,7 +96,7 @@ func handleSingleTorrent(requestPath string, t *torrent.TorrentManager) (*string
|
||||
sort.Strings(filenames)
|
||||
for _, filename := range filenames {
|
||||
file, _ := tor.SelectedFiles.Get(filename)
|
||||
if file.Link == "" {
|
||||
if file == nil || file.Link == "" {
|
||||
// will be caught by torrent manager's repairAll
|
||||
// just skip it for now
|
||||
continue
|
||||
|
||||
@@ -260,13 +260,13 @@ func (t *TorrentManager) startRefreshJob() {
|
||||
|
||||
noInfoCount := 0
|
||||
allTorrents, _ := t.DirectoryMap.Get("__all__")
|
||||
var retain []string
|
||||
retain := make(map[string]bool)
|
||||
for info := range torrentsChan {
|
||||
if info == nil {
|
||||
noInfoCount++
|
||||
continue
|
||||
}
|
||||
retain = append(retain, info.AccessKey)
|
||||
retain[info.AccessKey] = true
|
||||
if torrent, exists := allTorrents.Get(info.AccessKey); exists {
|
||||
mainTorrent := t.mergeToMain(torrent, info)
|
||||
allTorrents.Set(info.AccessKey, mainTorrent)
|
||||
@@ -305,25 +305,12 @@ func (t *TorrentManager) startRefreshJob() {
|
||||
})
|
||||
|
||||
// delete torrents that no longer exist
|
||||
var toDelete []string
|
||||
allTorrents.IterCb(func(_ string, torrent *Torrent) {
|
||||
found := false
|
||||
for _, accessKey := range retain {
|
||||
if torrent.AccessKey == accessKey {
|
||||
found = true
|
||||
break
|
||||
accessKeys := allTorrents.Keys()
|
||||
for _, oldAccessKey := range accessKeys {
|
||||
if _, ok := retain[oldAccessKey]; !ok {
|
||||
allTorrents.Remove(oldAccessKey)
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
toDelete = append(toDelete, torrent.AccessKey)
|
||||
}
|
||||
})
|
||||
for _, accessKey := range toDelete {
|
||||
t.DirectoryMap.IterCb(func(_ string, torrents cmap.ConcurrentMap[string, *Torrent]) {
|
||||
torrents.Remove(accessKey)
|
||||
})
|
||||
}
|
||||
// end delete torrents that no longer exist
|
||||
|
||||
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user