From 9aee85e5031a7f1c74f5668ed0f422cc6610c055 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Mon, 26 Apr 2021 11:48:41 +0200 Subject: [PATCH] Remove OCS share cache default TTL --- .../services/owncloud/ocs/config/config.go | 4 ---- .../handlers/apps/sharing/shares/public.go | 6 +++-- .../handlers/apps/sharing/shares/shares.go | 24 ++++++++++++------- .../ocs/handlers/apps/sharing/shares/user.go | 6 +++-- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/internal/http/services/owncloud/ocs/config/config.go b/internal/http/services/owncloud/ocs/config/config.go index f5361ece7b..3d8f73b0b3 100644 --- a/internal/http/services/owncloud/ocs/config/config.go +++ b/internal/http/services/owncloud/ocs/config/config.go @@ -64,9 +64,5 @@ func (c *Config) Init() { c.ResourceInfoCacheSize = 1000000 } - if c.ResourceInfoCacheTTL == 0 { - c.ResourceInfoCacheTTL = 86400 - } - c.GatewaySvc = sharedconf.GetGatewaySVC(c.GatewaySvc) } diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go index 5acd6b4709..e574551d4e 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/public.go @@ -163,7 +163,7 @@ func (h *Handler) listPublicShares(r *http.Request, filters []*link.ListPublicSh var info *provider.ResourceInfo for _, share := range res.GetShare() { key := wrapResourceID(share.ResourceId) - if infoIf, err := h.resourceInfoCache.Get(key); err == nil { + if infoIf, err := h.resourceInfoCache.Get(key); h.resourceInfoCacheTTL > 0 && err == nil { log.Debug().Msgf("cache hit for resource %+v", share.ResourceId) info = infoIf.(*provider.ResourceInfo) } else { @@ -181,7 +181,9 @@ func (h *Handler) listPublicShares(r *http.Request, filters []*link.ListPublicSh continue } info = statResponse.Info - _ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL) + if h.resourceInfoCacheTTL > 0 { + _ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL) + } } sData := conversions.PublicShare2ShareData(share, r, h.publicURL) diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index 9f41fe75fc..1e25a9e0a5 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -399,7 +399,7 @@ func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID strin var info *provider.ResourceInfo key := wrapResourceID(resourceID) - if infoIf, err := h.resourceInfoCache.Get(key); err == nil { + if infoIf, err := h.resourceInfoCache.Get(key); h.resourceInfoCacheTTL > 0 && err == nil { logger.Debug().Msgf("cache hit for resource %+v", resourceID) info = infoIf.(*provider.ResourceInfo) } else { @@ -425,7 +425,9 @@ func (h *Handler) getShare(w http.ResponseWriter, r *http.Request, shareID strin return } info = statResponse.Info - _ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL) + if h.resourceInfoCacheTTL > 0 { + _ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL) + } } err = h.addFileInfo(ctx, share, info) @@ -609,7 +611,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { // prefix the path with the owners home, because ocs share requests are relative to the home dir target := path.Join(h.homeNamespace, r.FormValue("path")) - if infoIf, err := h.resourceInfoCache.Get(target); err == nil { + if infoIf, err := h.resourceInfoCache.Get(target); h.resourceInfoCacheTTL > 0 && err == nil { logger.Debug().Msgf("cache hit for resource %+v", target) pinfo = infoIf.(*provider.ResourceInfo) } else { @@ -640,7 +642,9 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { } pinfo = statRes.GetInfo() - _ = h.resourceInfoCache.SetWithExpire(target, pinfo, time.Second*h.resourceInfoCacheTTL) + if h.resourceInfoCacheTTL > 0 { + _ = h.resourceInfoCache.SetWithExpire(target, pinfo, time.Second*h.resourceInfoCacheTTL) + } } } @@ -682,7 +686,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { info = pinfo } else { key := wrapResourceID(rs.Share.ResourceId) - if infoIf, err := h.resourceInfoCache.Get(key); err == nil { + if infoIf, err := h.resourceInfoCache.Get(key); h.resourceInfoCacheTTL > 0 && err == nil { logger.Debug().Msgf("cache hit for resource %+v", rs.Share.ResourceId) info = infoIf.(*provider.ResourceInfo) } else { @@ -702,7 +706,9 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) { } info = statRes.GetInfo() - _ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL) + if h.resourceInfoCacheTTL > 0 { + _ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL) + } } } @@ -802,7 +808,7 @@ func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix stri } target := path.Join(prefix, r.FormValue("path")) - if infoIf, err := h.resourceInfoCache.Get(target); err == nil { + if infoIf, err := h.resourceInfoCache.Get(target); h.resourceInfoCacheTTL > 0 && err == nil { info = infoIf.(*provider.ResourceInfo) } else { statReq := &provider.StatRequest{ @@ -830,7 +836,9 @@ func (h *Handler) addFilters(w http.ResponseWriter, r *http.Request, prefix stri } info = res.Info - _ = h.resourceInfoCache.SetWithExpire(target, info, time.Second*h.resourceInfoCacheTTL) + if h.resourceInfoCacheTTL > 0 { + _ = h.resourceInfoCache.SetWithExpire(target, info, time.Second*h.resourceInfoCacheTTL) + } } collaborationFilters = append(collaborationFilters, &collaboration.ListSharesRequest_Filter{ diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go index 886262271e..cac4cf61f8 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go @@ -181,7 +181,7 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.ListS var info *provider.ResourceInfo key := wrapResourceID(s.ResourceId) - if infoIf, err := h.resourceInfoCache.Get(key); err == nil { + if infoIf, err := h.resourceInfoCache.Get(key); h.resourceInfoCacheTTL > 0 && err == nil { log.Debug().Msgf("cache hit for resource %+v", s.ResourceId) info = infoIf.(*provider.ResourceInfo) } else { @@ -198,7 +198,9 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.ListS continue } info = statResponse.Info - _ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL) + if h.resourceInfoCacheTTL > 0 { + _ = h.resourceInfoCache.SetWithExpire(key, info, time.Second*h.resourceInfoCacheTTL) + } } if err := h.addFileInfo(ctx, data, info); err != nil {