Skip to content

Commit

Permalink
fix registry caching
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Jan 10, 2022
1 parent c05e074 commit d646792
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-registry-caching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: fix registry caching

We now cache space lookups per user.

https://github.com/cs3org/reva/pull/2427
10 changes: 7 additions & 3 deletions internal/grpc/services/gateway/storageprovidercache.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ type cachedRegistryClient struct {
func (c *cachedRegistryClient) ListStorageProviders(ctx context.Context, in *registry.ListStorageProvidersRequest, opts ...grpc.CallOption) (*registry.ListStorageProvidersResponse, error) {
cache := c.caches[listproviders]

key := sdk.DecodeOpaqueMap(in.Opaque)["storage_id"]
user := ctxpkg.ContextMustGetUser(ctx)

storageID := sdk.DecodeOpaqueMap(in.Opaque)["storage_id"]

key := user.GetId().GetOpaqueId() + storageID
if key != "" {
s := &registry.ListStorageProvidersResponse{}
if err := pullFromCache(cache, key, s); err == nil {
Expand All @@ -176,9 +180,9 @@ func (c *cachedRegistryClient) ListStorageProviders(ctx context.Context, in *reg
switch {
case err != nil:
return nil, err
case resp.Status.Code != rpc.Code_CODE_OK && resp.Status.Code != rpc.Code_CODE_NOT_FOUND:
case resp.Status.Code != rpc.Code_CODE_OK:
return resp, nil
case key == "":
case storageId == "":
return resp, nil
default:
return resp, pushToCache(cache, key, resp)
Expand Down

0 comments on commit d646792

Please sign in to comment.