diff --git a/internal/http/services/owncloud/ocs/config/config.go b/internal/http/services/owncloud/ocs/config/config.go index 3d8f73b0b36..20d785c0116 100644 --- a/internal/http/services/owncloud/ocs/config/config.go +++ b/internal/http/services/owncloud/ocs/config/config.go @@ -25,17 +25,19 @@ import ( // Config holds the config options that need to be passed down to all ocs handlers type Config struct { - Prefix string `mapstructure:"prefix"` - Config data.ConfigData `mapstructure:"config"` - Capabilities data.CapabilitiesData `mapstructure:"capabilities"` - GatewaySvc string `mapstructure:"gatewaysvc"` - DefaultUploadProtocol string `mapstructure:"default_upload_protocol"` - UserAgentChunkingMap map[string]string `mapstructure:"user_agent_chunking_map"` - SharePrefix string `mapstructure:"share_prefix"` - HomeNamespace string `mapstructure:"home_namespace"` - AdditionalInfoAttribute string `mapstructure:"additional_info_attribute"` - ResourceInfoCacheSize int `mapstructure:"resource_info_cache_size"` - ResourceInfoCacheTTL int `mapstructure:"resource_info_cache_ttl"` + Prefix string `mapstructure:"prefix"` + Config data.ConfigData `mapstructure:"config"` + Capabilities data.CapabilitiesData `mapstructure:"capabilities"` + GatewaySvc string `mapstructure:"gatewaysvc"` + DefaultUploadProtocol string `mapstructure:"default_upload_protocol"` + UserAgentChunkingMap map[string]string `mapstructure:"user_agent_chunking_map"` + SharePrefix string `mapstructure:"share_prefix"` + HomeNamespace string `mapstructure:"home_namespace"` + AdditionalInfoAttribute string `mapstructure:"additional_info_attribute"` + CacheWarmupDriver string `mapstructure:"cache_warmup_driver"` + CacheWarmupDrivers map[string]map[string]interface{} `mapstructure:"cache_warmup_drivers"` + ResourceInfoCacheSize int `mapstructure:"resource_info_cache_size"` + ResourceInfoCacheTTL int `mapstructure:"resource_info_cache_ttl"` } // Init sets sane defaults 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 1e25a9e0a54..ebcc9a7895f 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 @@ -50,6 +50,8 @@ import ( "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/pkg/rhttp/router" + "github.com/cs3org/reva/pkg/share/cache" + "github.com/cs3org/reva/pkg/share/cache/registry" "github.com/pkg/errors" ) @@ -72,6 +74,13 @@ type userIdentifiers struct { Mail string } +func getCacheWarmupManager(c *config.Config) (cache.Warmup, error) { + if f, ok := registry.NewFuncs[c.CacheWarmupDriver]; ok { + return f(c.CacheWarmupDrivers[c.CacheWarmupDriver]) + } + return nil, fmt.Errorf("driver not found: %s", c.CacheWarmupDriver) +} + // Init initializes this and any contained handlers func (h *Handler) Init(c *config.Config) error { h.gatewayAddr = c.GatewaySvc @@ -87,9 +96,25 @@ func (h *Handler) Init(c *config.Config) error { h.resourceInfoCache = gcache.New(c.ResourceInfoCacheSize).LFU().Build() + if h.resourceInfoCacheTTL > 0 { + cwm, _ := getCacheWarmupManager(c) + go h.startCacheWarmup(cwm) + } + return nil } +func (h *Handler) startCacheWarmup(c cache.Warmup) { + infos, err := c.GetResourceInfos() + if err != nil { + return + } + for _, r := range infos { + key := wrapResourceID(r.Id) + _ = h.resourceInfoCache.SetWithExpire(key, r, time.Second*h.resourceInfoCacheTTL) + } +} + func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { log := appctx.GetLogger(r.Context()) diff --git a/pkg/share/cache/cache.go b/pkg/share/cache/cache.go index 9b3f63f41d5..8e2023873be 100644 --- a/pkg/share/cache/cache.go +++ b/pkg/share/cache/cache.go @@ -22,7 +22,7 @@ import ( provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" ) -// FS is the interface to implement cache warmup strategies. +// Warmup is the interface to implement cache warmup strategies. type Warmup interface { GetResourceInfos() ([]*provider.ResourceInfo, error) }