diff --git a/pkg/filemanager/fs/dbfs/dbfs.go b/pkg/filemanager/fs/dbfs/dbfs.go index f1c74503..1f194919 100644 --- a/pkg/filemanager/fs/dbfs/dbfs.go +++ b/pkg/filemanager/fs/dbfs/dbfs.go @@ -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") diff --git a/pkg/filemanager/fs/dbfs/options.go b/pkg/filemanager/fs/dbfs/options.go index 98b4ccb2..74d3698b 100644 --- a/pkg/filemanager/fs/dbfs/options.go +++ b/pkg/filemanager/fs/dbfs/options.go @@ -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) { diff --git a/service/explorer/file.go b/service/explorer/file.go index 98dbe63b..4a22c47b 100644 --- a/service/explorer/file.go +++ b/service/explorer/file.go @@ -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"` } ) @@ -639,12 +640,15 @@ func (s *GetFileInfoService) Get(c *gin.Context) (*FileResponse, error) { return nil, serializer.NewError(serializer.CodeParamErr, "unknown uri", err) } - opts := []fs.Option{dbfs.WithFilePublicMetadata(), dbfs.WithNotRoot()} + opts := []fs.Option{dbfs.WithFilePublicMetadata()} if s.ExtendedInfo { opts = append(opts, dbfs.WithExtendedInfo(), dbfs.WithEntityUser(), dbfs.WithFileShareIfOwned()) } if s.FolderSummary { opts = append(opts, dbfs.WithLoadFolderSummary()) + if s.FolderSummaryBypassCache { + opts = append(opts, dbfs.WithBypassFolderSummaryCache()) + } } file, err := m.Get(c, uri, opts...)