diff options
| author | 2025-07-01 16:00:04 +0200 | |
|---|---|---|
| committer | 2025-07-01 16:00:04 +0200 | |
| commit | 4f2aa792b33fdd5fb4b22dec813b3668d7190522 (patch) | |
| tree | 1148a9322d04bf43c1c159df3079fb1790c5c154 /internal/config | |
| parent | [chore] update go dependencies (#4304) (diff) | |
| download | gotosocial-4f2aa792b33fdd5fb4b22dec813b3668d7190522.tar.xz | |
[performance] add statusfilter cache to cache calculated status filtering results (#4303)
this adds another 'filter' type cache, similar to the visibility and mute caches, to cache the results of status filtering checks. for the moment this keeps all the check calls themselves within the frontend typeconversion code, but i may move this out of the typeconverter in a future PR (also removing the ErrHideStatus means of propagating a hidden status).
also tweaks some of the cache invalidation hooks to not make unnecessary calls.
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4303
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 1 | ||||
| -rw-r--r-- | internal/config/defaults.go | 3 | ||||
| -rw-r--r-- | internal/config/helpers.gen.go | 47 |
3 files changed, 49 insertions, 2 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 528000478..8139770e0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -267,6 +267,7 @@ type CacheConfiguration struct { WebPushSubscriptionMemRatio float64 `name:"web-push-subscription-mem-ratio"` WebPushSubscriptionIDsMemRatio float64 `name:"web-push-subscription-ids-mem-ratio"` MutesMemRatio float64 `name:"mutes-mem-ratio"` + StatusFilterMemRatio float64 `name:"status-filter-mem-ratio"` VisibilityMemRatio float64 `name:"visibility-mem-ratio"` } diff --git a/internal/config/defaults.go b/internal/config/defaults.go index 82de65bb7..1540cc76b 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -233,8 +233,9 @@ var Defaults = Configuration{ WebfingerMemRatio: 0.1, WebPushSubscriptionMemRatio: 1, WebPushSubscriptionIDsMemRatio: 1, - VisibilityMemRatio: 2, MutesMemRatio: 2, + StatusFilterMemRatio: 7, + VisibilityMemRatio: 2, }, HTTPClient: HTTPClientConfiguration{ diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go index 7dfe1db23..36dd927f8 100644 --- a/internal/config/helpers.gen.go +++ b/internal/config/helpers.gen.go @@ -211,6 +211,7 @@ const ( CacheWebPushSubscriptionMemRatioFlag = "cache-web-push-subscription-mem-ratio" CacheWebPushSubscriptionIDsMemRatioFlag = "cache-web-push-subscription-ids-mem-ratio" CacheMutesMemRatioFlag = "cache-mutes-mem-ratio" + CacheStatusFilterMemRatioFlag = "cache-status-filter-mem-ratio" CacheVisibilityMemRatioFlag = "cache-visibility-mem-ratio" AdminAccountUsernameFlag = "username" AdminAccountEmailFlag = "email" @@ -404,11 +405,12 @@ func (cfg *Configuration) RegisterFlags(flags *pflag.FlagSet) { flags.Float64("cache-web-push-subscription-mem-ratio", cfg.Cache.WebPushSubscriptionMemRatio, "") flags.Float64("cache-web-push-subscription-ids-mem-ratio", cfg.Cache.WebPushSubscriptionIDsMemRatio, "") flags.Float64("cache-mutes-mem-ratio", cfg.Cache.MutesMemRatio, "") + flags.Float64("cache-status-filter-mem-ratio", cfg.Cache.StatusFilterMemRatio, "") flags.Float64("cache-visibility-mem-ratio", cfg.Cache.VisibilityMemRatio, "") } func (cfg *Configuration) MarshalMap() map[string]any { - cfgmap := make(map[string]any, 190) + cfgmap := make(map[string]any, 191) cfgmap["log-level"] = cfg.LogLevel cfgmap["log-timestamp-format"] = cfg.LogTimestampFormat cfgmap["log-db-queries"] = cfg.LogDbQueries @@ -591,6 +593,7 @@ func (cfg *Configuration) MarshalMap() map[string]any { cfgmap["cache-web-push-subscription-mem-ratio"] = cfg.Cache.WebPushSubscriptionMemRatio cfgmap["cache-web-push-subscription-ids-mem-ratio"] = cfg.Cache.WebPushSubscriptionIDsMemRatio cfgmap["cache-mutes-mem-ratio"] = cfg.Cache.MutesMemRatio + cfgmap["cache-status-filter-mem-ratio"] = cfg.Cache.StatusFilterMemRatio cfgmap["cache-visibility-mem-ratio"] = cfg.Cache.VisibilityMemRatio cfgmap["username"] = cfg.AdminAccountUsername cfgmap["email"] = cfg.AdminAccountEmail @@ -2098,6 +2101,14 @@ func (cfg *Configuration) UnmarshalMap(cfgmap map[string]any) error { } } + if ival, ok := cfgmap["cache-status-filter-mem-ratio"]; ok { + var err error + cfg.Cache.StatusFilterMemRatio, err = cast.ToFloat64E(ival) + if err != nil { + return fmt.Errorf("error casting %#v -> float64 for 'cache-status-filter-mem-ratio': %w", ival, err) + } + } + if ival, ok := cfgmap["cache-visibility-mem-ratio"]; ok { var err error cfg.Cache.VisibilityMemRatio, err = cast.ToFloat64E(ival) @@ -6197,6 +6208,28 @@ func GetCacheMutesMemRatio() float64 { return global.GetCacheMutesMemRatio() } // SetCacheMutesMemRatio safely sets the value for global configuration 'Cache.MutesMemRatio' field func SetCacheMutesMemRatio(v float64) { global.SetCacheMutesMemRatio(v) } +// GetCacheStatusFilterMemRatio safely fetches the Configuration value for state's 'Cache.StatusFilterMemRatio' field +func (st *ConfigState) GetCacheStatusFilterMemRatio() (v float64) { + st.mutex.RLock() + v = st.config.Cache.StatusFilterMemRatio + st.mutex.RUnlock() + return +} + +// SetCacheStatusFilterMemRatio safely sets the Configuration value for state's 'Cache.StatusFilterMemRatio' field +func (st *ConfigState) SetCacheStatusFilterMemRatio(v float64) { + st.mutex.Lock() + defer st.mutex.Unlock() + st.config.Cache.StatusFilterMemRatio = v + st.reloadToViper() +} + +// GetCacheStatusFilterMemRatio safely fetches the value for global configuration 'Cache.StatusFilterMemRatio' field +func GetCacheStatusFilterMemRatio() float64 { return global.GetCacheStatusFilterMemRatio() } + +// SetCacheStatusFilterMemRatio safely sets the value for global configuration 'Cache.StatusFilterMemRatio' field +func SetCacheStatusFilterMemRatio(v float64) { global.SetCacheStatusFilterMemRatio(v) } + // GetCacheVisibilityMemRatio safely fetches the Configuration value for state's 'Cache.VisibilityMemRatio' field func (st *ConfigState) GetCacheVisibilityMemRatio() (v float64) { st.mutex.RLock() @@ -6433,6 +6466,7 @@ func (st *ConfigState) GetTotalOfMemRatios() (total float64) { total += st.config.Cache.WebPushSubscriptionMemRatio total += st.config.Cache.WebPushSubscriptionIDsMemRatio total += st.config.Cache.MutesMemRatio + total += st.config.Cache.StatusFilterMemRatio total += st.config.Cache.VisibilityMemRatio st.mutex.RUnlock() return @@ -7396,6 +7430,17 @@ func flattenConfigMap(cfgmap map[string]any) { } for _, key := range [][]string{ + {"cache", "status-filter-mem-ratio"}, + } { + ival, ok := mapGet(cfgmap, key...) + if ok { + cfgmap["cache-status-filter-mem-ratio"] = ival + nestedKeys[key[0]] = struct{}{} + break + } + } + + for _, key := range [][]string{ {"cache", "visibility-mem-ratio"}, } { ival, ok := mapGet(cfgmap, key...) |
