Skip to content

Commit

Permalink
Add comment about copying context
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Oct 26, 2021
1 parent 0cfacfd commit af3db78
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/http/services/owncloud/ocs/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (s *svc) cacheWarmup(w http.ResponseWriter, r *http.Request) {
tkn := ctxpkg.ContextMustGetToken(r.Context())
log := appctx.GetLogger(r.Context())

// We make a copy of the context because the original one comes with its cancel channel,
// so once the initial request is finished, this ctx gets cancelled as well.
// And in most of the cases, the warmup takes a longer amount of time to complete than the original request.
// TODO: Check if we can come up with a better solution, eg, https://stackoverflow.com/a/54132324
ctx := context.Background()
ctx = appctx.WithLogger(ctx, log)
ctx = ctxpkg.ContextSetUser(ctx, u)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ type Handler struct {
homeNamespace string
additionalInfoTemplate *template.Template
userIdentifierCache *ttlcache.Cache
userIdentifierCacheTTL time.Duration
resourceInfoCache gcache.Cache
resourceInfoCacheTTL time.Duration
}
Expand Down

0 comments on commit af3db78

Please sign in to comment.