Skip to content

Commit c739713

Browse files
kobergjbutonic
authored andcommitted
fix statcache logic (cs3org#2440)
Signed-off-by: jkoberg <[email protected]>
1 parent 1ed9c9f commit c739713

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: changelog/unreleased/improve_statcache.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: Add ArbitraryMetadataKeys to statcache key
2+
3+
Otherwise stating with and without them would return the same result (because it is cached)
4+
5+
https://github.com/cs3org/reva/pull/2440

Diff for: internal/grpc/services/gateway/storageprovidercache.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,24 @@ type cachedAPIClient struct {
211211
// generates a user specific key pointing to ref - used for statcache
212212
// a key looks like: uid:1234-1233!sid:5678-5677!oid:9923-9934!path:/path/to/source
213213
// as you see it adds "uid:"/"sid:"/"oid:" prefixes to the uuids so they can be differentiated
214-
func statKey(user *userpb.User, ref *provider.Reference) string {
214+
func statKey(user *userpb.User, ref *provider.Reference, metaDataKeys []string) string {
215215
if ref == nil || ref.ResourceId == nil || ref.ResourceId.StorageId == "" {
216216
return ""
217217
}
218218

219-
return "uid" + user.Id.OpaqueId + "!sid:" + ref.ResourceId.StorageId + "!oid:" + ref.ResourceId.OpaqueId + "!path:" + ref.Path
219+
key := "uid" + user.Id.OpaqueId + "!sid:" + ref.ResourceId.StorageId + "!oid:" + ref.ResourceId.OpaqueId + "!path:" + ref.Path
220+
for _, k := range metaDataKeys {
221+
key += "!mdk:" + k
222+
}
223+
224+
return key
220225
}
221226

222227
// Stat looks in cache first before forwarding to storage provider
223228
func (c *cachedAPIClient) Stat(ctx context.Context, in *provider.StatRequest, opts ...grpc.CallOption) (*provider.StatResponse, error) {
224229
cache := c.caches[stat]
225230

226-
key := statKey(ctxpkg.ContextMustGetUser(ctx), in.Ref)
231+
key := statKey(ctxpkg.ContextMustGetUser(ctx), in.Ref, in.ArbitraryMetadataKeys)
227232
if key != "" {
228233
s := &provider.StatResponse{}
229234
if err := pullFromCache(cache, key, s); err == nil {

0 commit comments

Comments
 (0)