feat: allow calculate root folder summary (adapt for https://github.com/cloudreve/frontend/pull/333)

pull/3407/head
Darren Yu 1 week ago
parent 58b83ea1e4
commit d5e1837b04
No known key found for this signature in database
GPG Key ID: 2D69AA5646405984

@ -455,13 +455,20 @@ func (f *DBFS) Get(ctx context.Context, path *fs.URI, opts ...fs.Option) (fs.Fil
return nil, fs.ErrOwnerOnly
}
// first, try to load from cache
summary, ok := f.cache.Get(fmt.Sprintf("%s%d", folderSummaryCachePrefix, target.ID()))
if ok {
summaryTyped := summary.(fs.FolderSummary)
target.FileFolderSummary = &summaryTyped
} else {
// cache miss, walk the folder to get the summary
loadFolderSummaryDone := false
// first, try to load from cache if cache is not bypassed
if !o.bypassFolderSummaryCache {
summary, ok := f.cache.Get(fmt.Sprintf("%s%d", folderSummaryCachePrefix, target.ID()))
if ok {
summaryTyped := summary.(fs.FolderSummary)
target.FileFolderSummary = &summaryTyped
loadFolderSummaryDone = true
}
}
if !loadFolderSummaryDone {
// cache miss or bypass, walk the folder to get the summary
newSummary := &fs.FolderSummary{Completed: true}
if f.user.Edges.Group == nil {
return nil, fmt.Errorf("user group not loaded")

@ -9,6 +9,7 @@ import (
type dbfsOption struct {
*fs.FsOption
loadFolderSummary bool
bypassFolderSummaryCache bool
extendedInfo bool
loadFilePublicMetadata bool
loadFileShareIfOwned bool
@ -173,6 +174,14 @@ func WithLoadFolderSummary() fs.Option {
})
}
// WithBypassFolderSummaryCache enables bypassing existing cached folder summary.
// Newly calculated summary will still be written to cache.
func WithBypassFolderSummaryCache() fs.Option {
return optionFunc(func(o *dbfsOption) {
o.bypassFolderSummaryCache = true
})
}
// WithEntityUser enables loading entity user.
func WithEntityUser() fs.Option {
return optionFunc(func(o *dbfsOption) {

@ -603,10 +603,11 @@ func (s *UnlockFileService) Unlock(c *gin.Context) error {
type (
GetFileInfoParameterCtx struct{}
GetFileInfoService struct {
Uri string `form:"uri"`
ID string `form:"id"`
ExtendedInfo bool `form:"extended"`
FolderSummary bool `form:"folder_summary"`
Uri string `form:"uri"`
ID string `form:"id"`
ExtendedInfo bool `form:"extended"`
FolderSummary bool `form:"folder_summary"`
FolderSummaryBypassCache bool `form:"nocache"`
}
)
@ -645,6 +646,9 @@ func (s *GetFileInfoService) Get(c *gin.Context) (*FileResponse, error) {
}
if s.FolderSummary {
opts = append(opts, dbfs.WithLoadFolderSummary())
if s.FolderSummaryBypassCache {
opts = append(opts, dbfs.WithBypassFolderSummaryCache())
}
}
file, err := m.Get(c, uri, opts...)

Loading…
Cancel
Save