Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use updated etag of home directory even if it is cached #1416

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/etag-cache-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: Use updated etag of home directory even if it is cached

We cache the home directory and shares folder etags as calculating these is an
expensive process. But if these directories were updated after the previously
calculated etag was cached, we can ignore this calculation and directly return
the new one.

https://github.com/cs3org/reva/pull/1416
29 changes: 23 additions & 6 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/cs3org/reva/pkg/storage/utils/etag"
"github.com/cs3org/reva/pkg/storage/utils/templates"
"github.com/cs3org/reva/pkg/user"
"github.com/cs3org/reva/pkg/utils"
"github.com/dgrijalva/jwt-go"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -985,12 +986,17 @@ func (s *svc) statHome(ctx context.Context) (*provider.StatResponse, error) {
}, nil
}

if resEtag, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil {
statRes.Info.Etag = resEtag.(string)
if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil {
resMtime := utils.TSToTime(statRes.Info.Mtime)
resEtag := etagIface.(etagWithTS)
// Use the updated etag if the home folder has been modified
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if resMtime.Before(resEtag.Timestamp) {
statRes.Info.Etag = resEtag.Etag
}
} else {
statRes.Info.Etag = etag.GenerateEtagFromResources(statRes.Info, []*provider.ResourceInfo{statSharedFolder.Info})
if s.c.EtagCacheTTL > 0 {
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, statRes.Info.Etag)
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, etagWithTS{statRes.Info.Etag, time.Now()})
}
}

Expand Down Expand Up @@ -1029,12 +1035,18 @@ func (s *svc) statSharesFolder(ctx context.Context) (*provider.StatResponse, err
}, nil
}

if resEtag, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil {
statRes.Info.Etag = resEtag.(string)
if etagIface, err := s.etagCache.Get(statRes.Info.Owner.OpaqueId + ":" + statRes.Info.Path); err == nil {
resMtime := utils.TSToTime(statRes.Info.Mtime)
resEtag := etagIface.(etagWithTS)
// Use the updated etag if the shares folder has been modified, i.e., a new
// reference has been created.
if resMtime.Before(resEtag.Timestamp) {
statRes.Info.Etag = resEtag.Etag
}
} else {
statRes.Info.Etag = etag.GenerateEtagFromResources(statRes.Info, lsRes.Infos)
if s.c.EtagCacheTTL > 0 {
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, statRes.Info.Etag)
_ = s.etagCache.Set(statRes.Info.Owner.OpaqueId+":"+statRes.Info.Path, etagWithTS{statRes.Info.Etag, time.Now()})
}
}
return statRes, nil
Expand Down Expand Up @@ -1852,3 +1864,8 @@ func (s *svc) getStorageProvider(ctx context.Context, ref *provider.Reference) (

return res.Provider, nil
}

type etagWithTS struct {
Etag string
Timestamp time.Time
}