Remove ristretto cache

This commit is contained in:
Ben Sarmiento
2023-12-06 01:11:58 +01:00
parent 121a28d46f
commit 4b8fd82acd
7 changed files with 63 additions and 226 deletions

View File

@@ -14,7 +14,7 @@ func HandleDeleteTorrent(directory, torrentName string, t *torrent.TorrentManage
if !torrents.Has(torrentName) {
return fmt.Errorf("cannot find torrent %s", torrentName)
}
t.Delete(torrentName, true, true)
t.Delete(torrentName, true)
return nil
}
@@ -33,10 +33,9 @@ func HandleDeleteFile(directory, torrentName, fileName string, t *torrent.Torren
}
file.Link = "unselect"
if t.CheckDeletedState(torrent) {
t.Delete(torrentName, true, true)
} else {
updatedPaths := t.UpdateTorrentResponseCache(torrent)
t.TriggerHookOnLibraryUpdate(updatedPaths)
t.Delete(torrentName, true)
}
// todo: triggeer an update ???
// t.TriggerHookOnLibraryUpdate(updatedPaths)
return nil
}

View File

@@ -13,9 +13,7 @@ import (
func HandleListDirectories(t *torrent.TorrentManager) (*string, error) {
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">"
// initial response is the directory itself
davDoc += dav.BaseDirectory("", "")
directories := t.DirectoryMap.Keys()
sort.Strings(directories)
for _, directory := range directories {
@@ -24,7 +22,6 @@ func HandleListDirectories(t *torrent.TorrentManager) (*string, error) {
}
davDoc += dav.Directory(directory, "")
}
davDoc += "</d:multistatus>"
return &davDoc, nil
}
@@ -35,21 +32,15 @@ func HandleListTorrents(directory string, t *torrent.TorrentManager, log *zap.Su
return nil, fmt.Errorf("cannot find directory %s", directory)
}
if resp, ok := t.ResponseCache.Get(directory + ".dav"); !ok {
log.Debugf("Generating xml for directory %s", directory)
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">"
davDoc += dav.Directory("", "")
directories := t.DirectoryMap.Keys()
sort.Strings(directories)
for _, directory := range directories {
davDoc += dav.Directory(directory, "")
}
davDoc += "</d:multistatus>"
return &davDoc, nil
} else {
davDoc := resp.(string)
return &davDoc, nil
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">"
davDoc += dav.Directory("", "")
directories := t.DirectoryMap.Keys()
sort.Strings(directories)
for _, directory := range directories {
davDoc += dav.Directory(directory, "")
}
davDoc += "</d:multistatus>"
return &davDoc, nil
}
func HandleListFiles(directory, torrentName string, t *torrent.TorrentManager, log *zap.SugaredLogger) (*string, error) {
@@ -62,22 +53,16 @@ func HandleListFiles(directory, torrentName string, t *torrent.TorrentManager, l
return nil, fmt.Errorf("cannot find torrent %s", torrentName)
}
if resp, ok := t.ResponseCache.Get(directory + "/" + torrentName + ".dav"); !ok {
log.Debugf("Generating xml for torrent %s", torrentName)
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">" + dav.BaseDirectory(filepath.Join(directory, tor.AccessKey), tor.LatestAdded)
filenames := tor.SelectedFiles.Keys()
sort.Strings(filenames)
for _, filename := range filenames {
file, _ := tor.SelectedFiles.Get(filename)
if file == nil || !strings.HasPrefix(file.Link, "http") {
continue
}
davDoc += dav.File(filename, file.Bytes, file.Ended)
davDoc := "<?xml version=\"1.0\" encoding=\"utf-8\"?><d:multistatus xmlns:d=\"DAV:\">" + dav.BaseDirectory(filepath.Join(directory, tor.AccessKey), tor.LatestAdded)
filenames := tor.SelectedFiles.Keys()
sort.Strings(filenames)
for _, filename := range filenames {
file, ok := tor.SelectedFiles.Get(filename)
if !ok || !strings.HasPrefix(file.Link, "http") {
continue
}
davDoc += "</d:multistatus>"
return &davDoc, nil
} else {
davDoc := resp.(string)
return &davDoc, nil
davDoc += dav.File(filename, file.Bytes, file.Ended)
}
davDoc += "</d:multistatus>"
return &davDoc, nil
}