fix: cache is modified while sorting (close #2340)

This commit is contained in:
Noah Hsu 2022-11-15 14:38:23 +08:00
parent 3fbdf6f022
commit 4dcaa24758
2 changed files with 5 additions and 1 deletions

View File

@ -24,7 +24,7 @@ func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error
return nil, errors.WithMessage(err, "failed get storage") return nil, errors.WithMessage(err, "failed get storage")
} }
} else { } else {
objs, err = op.List(ctx, storage, actualPath, model.ListArgs{ _objs, err := op.List(ctx, storage, actualPath, model.ListArgs{
ReqPath: path, ReqPath: path,
}, refresh...) }, refresh...)
if err != nil { if err != nil {
@ -33,6 +33,8 @@ func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error
return nil, errors.WithMessage(err, "failed get objs") return nil, errors.WithMessage(err, "failed get objs")
} }
} }
objs = make([]model.Obj, len(_objs))
copy(objs, _objs)
} }
if objs == nil { if objs == nil {
objs = virtualFiles objs = virtualFiles

View File

@ -60,8 +60,10 @@ func List(ctx context.Context, storage driver.Driver, path string, args model.Li
} }
if !storage.Config().NoCache { if !storage.Config().NoCache {
if len(files) > 0 { if len(files) > 0 {
log.Debugf("set cache: %s => %+v", key, files)
listCache.Set(key, files, cache.WithEx[[]model.Obj](time.Minute*time.Duration(storage.GetStorage().CacheExpiration))) listCache.Set(key, files, cache.WithEx[[]model.Obj](time.Minute*time.Duration(storage.GetStorage().CacheExpiration)))
} else { } else {
log.Debugf("del cache: %s", key)
listCache.Del(key) listCache.Del(key)
} }
} }