Skip to content

Commit 3b2c3f3

Browse files
committed
use listCache
1 parent fecd62f commit 3b2c3f3

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

internal/op/fs.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,6 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
177177
path = utils.FixAndCleanPath(path)
178178
log.Debugf("op.Get %s", path)
179179

180-
// get the obj directly without list so that we can reduce the io
181-
if g, ok := storage.(driver.Getter); ok {
182-
obj, err := g.Get(ctx, path)
183-
if err == nil {
184-
return model.WrapObjName(obj), nil
185-
}
186-
}
187-
188180
// is root folder
189181
if utils.PathEqual(path, "/") {
190182
var rootObj model.Obj
@@ -227,7 +219,24 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
227219

228220
// not root folder
229221
dir, name := stdpath.Split(path)
230-
files, err := List(ctx, storage, dir, model.ListArgs{})
222+
key := Key(storage, dir)
223+
if files, ok := listCache.Get(key); ok {
224+
log.Debugf("use cache when list %s", path)
225+
for _, f := range files {
226+
if f.GetName() == name {
227+
return f, nil
228+
}
229+
}
230+
}
231+
// get the obj directly without list so that we can reduce the io
232+
if g, ok := storage.(driver.Getter); ok {
233+
obj, err := g.Get(ctx, path)
234+
if err == nil {
235+
return model.WrapObjName(obj), nil
236+
}
237+
}
238+
239+
files, err := List(ctx, storage, dir, model.ListArgs{Refresh: true})
231240
if err != nil {
232241
return nil, errors.WithMessage(err, "failed get parent list")
233242
}

0 commit comments

Comments
 (0)