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