Skip to content

Commit

Permalink
Fix inefficient path based space lookup for public links
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed May 9, 2023
1 parent afacd4e commit 7b2810c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/unreleased/space-registry-path-filtering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fix public link lookup performance

Fix inefficient path based space lookup for public links

https://github.com/cs3org/reva/pull/3863
5 changes: 5 additions & 0 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSp
// TODO check for allowed filters
filters["mask"] = mask
}
path := utils.ReadPlainFromOpaque(req.Opaque, "path")
if mask != "" {
// TODO check for allowed filters
filters["path"] = path
}

for _, f := range req.Filters {
switch f.Type {
Expand Down
20 changes: 19 additions & 1 deletion pkg/storage/registry/spaces/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,30 @@ func (r *registry) findProvidersForAbsolutePathReference(ctx context.Context, pa
var spaces []*providerpb.StorageSpace
var err error

// check if any space in the provider has a valid mountpoint
containsRelatedSpace := false
for _, space := range provider.Spaces {
// either the mountpoint is a prefix of the path
if strings.HasPrefix(path, space.MountPoint) {
containsRelatedSpace = true
break
}
// or the path is a prefix of the mountpoint
if strings.HasPrefix(space.MountPoint, path) {
containsRelatedSpace = true
break
}
}
if !containsRelatedSpace {
continue
}

// when listing paths also return mountpoints
filters := []*providerpb.ListStorageSpacesRequest_Filter{
{
Type: providerpb.ListStorageSpacesRequest_Filter_TYPE_PATH,
Term: &providerpb.ListStorageSpacesRequest_Filter_Path{
Path: strings.TrimPrefix(path, p.ProviderPath),
Path: strings.TrimPrefix(path, p.ProviderPath), // FIXME this no longer has an effect as the p.Providerpath is always empty
},
},
{
Expand Down

0 comments on commit 7b2810c

Please sign in to comment.