Skip to content

Commit fdb3ae7

Browse files
committed
perf(alias): narrow cached backend paths
1 parent de0b9ed commit fdb3ae7

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

drivers/alias/driver.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ func (d *Alias) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
201201
dirPath := dirPaths[dirIndex]
202202
for _, obj := range tmp {
203203
name := obj.GetName()
204-
if _, exists := resolveMap[name]; !exists {
205-
paths := make([]string, 0, len(dirPaths)-dirIndex)
206-
for _, path := range dirPaths[dirIndex:] {
207-
paths = append(paths, stdpath.Join(path, name))
208-
}
209-
resolveMap[name] = newAliasResolved(paths, dirIndex > 0, obj)
204+
childPath := stdpath.Join(dirPath, name)
205+
if resolved, exists := resolveMap[name]; exists {
206+
resolved.paths = append(resolved.paths, childPath)
207+
resolveMap[name] = resolved
208+
} else {
209+
resolveMap[name] = newAliasResolved([]string{childPath}, dirIndex > 0, obj)
210210
}
211211
if _, exists := objMap[name]; exists {
212212
continue

drivers/alias/index.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,28 @@ func (d *Alias) getResolvedFromSearchIndex(ctx context.Context, roots []string,
2222
return aliasResolved{}, false
2323
}
2424
known := make(map[string]aliasSearchIndexState)
25+
paths := make([]string, 0, len(roots))
26+
firstIndex := -1
2527
for idx, root := range roots {
2628
rawPath := stdpath.Join(root, sub)
2729
_, exists, reliable := aliasSearchIndexPath(ctx, rawPath, known)
2830
if exists {
29-
paths := make([]string, 0, len(roots)-idx)
30-
for _, root := range roots[idx:] {
31-
paths = append(paths, stdpath.Join(root, sub))
31+
if firstIndex < 0 {
32+
firstIndex = idx
3233
}
33-
return aliasResolved{
34-
paths: paths,
35-
skipped: idx > 0,
36-
}, true
34+
paths = append(paths, rawPath)
3735
}
3836
if !reliable {
3937
return aliasResolved{}, false
4038
}
4139
}
42-
return aliasResolved{}, false
40+
if len(paths) == 0 {
41+
return aliasResolved{}, false
42+
}
43+
return aliasResolved{
44+
paths: paths,
45+
skipped: firstIndex > 0,
46+
}, true
4347
}
4448

4549
func aliasSearchIndexReady() bool {

drivers/alias/meta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Addition struct {
1616
ProviderPassThrough bool `json:"provider_pass_through" type:"bool" default:"false"`
1717
DetailsPassThrough bool `json:"details_pass_through" type:"bool" default:"false"`
1818
AliasCacheEnabled bool `json:"alias_cache_enabled" type:"bool" default:"false" help:"Cache aggregated Alias directory listings and resolved backend paths"`
19-
AliasCacheExpiration int `json:"alias_cache_expiration" default:"30" required:"false" type:"number" help:"Alias cache expiration in minutes"`
19+
AliasCacheExpiration int `json:"alias_cache_expiration" default:"30" required:"false" type:"number" help:"Alias cache expiration time (minutes)"`
2020
AliasCacheMaxEntries int `json:"alias_cache_max_entries" default:"0" required:"false" type:"number" help:"Maximum Alias cache entries. 0 means unlimited"`
2121
AliasListConcurrency int `json:"alias_list_concurrency" default:"1" required:"false" type:"number" help:"Maximum number of backend folders to list concurrently. 1 or less means serial listing"`
2222
}

0 commit comments

Comments
 (0)