diff --git a/changelog/unreleased/space-registry-path-filtering.md b/changelog/unreleased/space-registry-path-filtering.md new file mode 100644 index 0000000000..2db0abd78c --- /dev/null +++ b/changelog/unreleased/space-registry-path-filtering.md @@ -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/3866 diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 7c6c6a7205..54e72f20d6 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -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 { diff --git a/pkg/storage/registry/spaces/spaces.go b/pkg/storage/registry/spaces/spaces.go index 4ce986cf0c..0d031bb533 100644 --- a/pkg/storage/registry/spaces/spaces.go +++ b/pkg/storage/registry/spaces/spaces.go @@ -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 }, }, {