Skip to content

Commit

Permalink
fix registry caching (#2427)
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic authored Jan 10, 2022
1 parent 17ea34e commit 5be5f3c
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 5be5f3c

Please sign in to comment.