feat: use storm.Prefix to select all shares with path prefixes instead of listing all files
parent
7398478d29
commit
0ef534d4a6
|
@ -73,10 +73,7 @@ func resourceDeleteHandler(fileCache FileCache) handleFunc {
|
||||||
return errToStatus(err), err
|
return errToStatus(err), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete potential shares for this path
|
d.store.Share.DeleteWithPath(file.Path)
|
||||||
for _, path := range flatListFilePaths(file, d) {
|
|
||||||
d.store.Share.DeleteWithPath(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete thumbnails
|
// delete thumbnails
|
||||||
err = delThumbs(r.Context(), fileCache, file)
|
err = delThumbs(r.Context(), fileCache, file)
|
||||||
|
@ -337,41 +334,6 @@ func patchAction(ctx context.Context, action, src, dst string, d *data, fileCach
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func flatListFilePaths(fileInfo *files.FileInfo, d *data) []string {
|
|
||||||
var paths []string
|
|
||||||
|
|
||||||
paths = append(paths, fileInfo.Path)
|
|
||||||
|
|
||||||
if (!fileInfo.isDir) {
|
|
||||||
return paths
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, item := range fileInfo.Items {
|
|
||||||
// no need to add the directory's path here as it will provide itself in the next recursion
|
|
||||||
if (item.IsDir) {
|
|
||||||
file, err := files.NewFileInfo(&files.FileOptions{
|
|
||||||
Fs: item.Fs,
|
|
||||||
Path: item.Path + "/", // ensure we add the suffix "/" for a directory
|
|
||||||
Modify: false,
|
|
||||||
Expand: true,
|
|
||||||
ReadHeader: false,
|
|
||||||
Checker: d,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (err != nil) {
|
|
||||||
return paths
|
|
||||||
}
|
|
||||||
|
|
||||||
deeperFiles := flatListFilePaths(file, d)
|
|
||||||
paths = append(paths, deeperFiles...)
|
|
||||||
} else {
|
|
||||||
paths = append(paths, item.Path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return paths
|
|
||||||
}
|
|
||||||
|
|
||||||
type DiskUsageResponse struct {
|
type DiskUsageResponse struct {
|
||||||
Total uint64 `json:"total"`
|
Total uint64 `json:"total"`
|
||||||
Used uint64 `json:"used"`
|
Used uint64 `json:"used"`
|
||||||
|
|
|
@ -15,7 +15,7 @@ type StorageBackend interface {
|
||||||
Gets(path string, id uint) ([]*Link, error)
|
Gets(path string, id uint) ([]*Link, error)
|
||||||
Save(s *Link) error
|
Save(s *Link) error
|
||||||
Delete(hash string) error
|
Delete(hash string) error
|
||||||
DeleteWithPath(path string) error
|
DeleteWithPath(path string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Storage is a storage.
|
// Storage is a storage.
|
||||||
|
@ -120,6 +120,6 @@ func (s *Storage) Delete(hash string) error {
|
||||||
return s.back.Delete(hash)
|
return s.back.Delete(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) DeleteWithPath(path string) error {
|
func (s *Storage) DeleteWithPath(path string) {
|
||||||
return s.back.DeleteWithPath(path)
|
s.back.DeleteWithPath(path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,10 +76,10 @@ func (s shareBackend) Delete(hash string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shareBackend) DeleteWithPath(path string) error {
|
func (s shareBackend) DeleteWithPath(pathPrefix string) {
|
||||||
err := s.db.Select(q.Eq("Path", path)).Delete(&share.Link{})
|
var links []share.Link
|
||||||
if errors.Is(err, storm.ErrNotFound) {
|
s.db.Prefix("Path", pathPrefix, &links)
|
||||||
return nil
|
for _, link :=range links {
|
||||||
|
s.db.DeleteStruct(&share.Link{Hash: link.Hash})
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue