@@ -177,14 +177,6 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
177
177
path = utils .FixAndCleanPath (path )
178
178
log .Debugf ("op.Get %s" , path )
179
179
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
-
188
180
// is root folder
189
181
if utils .PathEqual (path , "/" ) {
190
182
var rootObj model.Obj
@@ -227,7 +219,24 @@ func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, er
227
219
228
220
// not root folder
229
221
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 })
231
240
if err != nil {
232
241
return nil , errors .WithMessage (err , "failed get parent list" )
233
242
}
0 commit comments