mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] support configuring database caches (#1246)
* update config generator to support nested structs, add cache configuration options * update envparsing test * add cache configuration to config parse tests * set cache configuration in testrig * move caches to sub-cache "gts" namespace, update envparsing, add cache config docs to example config Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
@@ -20,6 +20,7 @@ package config
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"codeberg.org/gruf/go-bytesize"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
@@ -129,6 +130,9 @@ type Configuration struct {
|
||||
AdvancedCookiesSamesite string `name:"advanced-cookies-samesite" usage:"'strict' or 'lax', see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite"`
|
||||
AdvancedRateLimitRequests int `name:"advanced-rate-limit-requests" usage:"Amount of HTTP requests to permit within a 5 minute window. 0 or less turns rate limiting off."`
|
||||
|
||||
// Cache configuration vars.
|
||||
Cache CacheConfiguration `name:"cache"`
|
||||
|
||||
// TODO: move these elsewhere, these are more ephemeral vs long-running flags like above
|
||||
AdminAccountUsername string `name:"username" usage:"the username to create/delete/etc"`
|
||||
AdminAccountEmail string `name:"email" usage:"the email address of this account"`
|
||||
@@ -137,7 +141,53 @@ type Configuration struct {
|
||||
AdminMediaPruneDryRun bool `name:"dry-run" usage:"perform a dry run and only log number of items eligible for pruning"`
|
||||
}
|
||||
|
||||
// MarshalMap will marshal current Configuration into a map structure (useful for JSON).
|
||||
type CacheConfiguration struct {
|
||||
GTS GTSCacheConfiguration `name:"gts"`
|
||||
}
|
||||
|
||||
type GTSCacheConfiguration struct {
|
||||
AccountMaxSize int `name:"account-max-size"`
|
||||
AccountTTL time.Duration `name:"account-ttl"`
|
||||
AccountSweepFreq time.Duration `name:"account-sweep-freq"`
|
||||
|
||||
BlockMaxSize int `name:"block-max-size"`
|
||||
BlockTTL time.Duration `name:"block-ttl"`
|
||||
BlockSweepFreq time.Duration `name:"block-sweep-freq"`
|
||||
|
||||
DomainBlockMaxSize int `name:"domain-block-max-size"`
|
||||
DomainBlockTTL time.Duration `name:"domain-block-ttl"`
|
||||
DomainBlockSweepFreq time.Duration `name:"domain-block-sweep-freq"`
|
||||
|
||||
EmojiMaxSize int `name:"emoji-max-size"`
|
||||
EmojiTTL time.Duration `name:"emoji-ttl"`
|
||||
EmojiSweepFreq time.Duration `name:"emoji-sweep-freq"`
|
||||
|
||||
EmojiCategoryMaxSize int `name:"emoji-category-max-size"`
|
||||
EmojiCategoryTTL time.Duration `name:"emoji-category-ttl"`
|
||||
EmojiCategorySweepFreq time.Duration `name:"emoji-category-sweep-freq"`
|
||||
|
||||
MentionMaxSize int `name:"mention-max-size"`
|
||||
MentionTTL time.Duration `name:"mention-ttl"`
|
||||
MentionSweepFreq time.Duration `name:"mention-sweep-freq"`
|
||||
|
||||
NotificationMaxSize int `name:"notification-max-size"`
|
||||
NotificationTTL time.Duration `name:"notification-ttl"`
|
||||
NotificationSweepFreq time.Duration `name:"notification-sweep-freq"`
|
||||
|
||||
StatusMaxSize int `name:"status-max-size"`
|
||||
StatusTTL time.Duration `name:"status-ttl"`
|
||||
StatusSweepFreq time.Duration `name:"status-sweep-freq"`
|
||||
|
||||
TombstoneMaxSize int `name:"tombstone-max-size"`
|
||||
TombstoneTTL time.Duration `name:"tombstone-ttl"`
|
||||
TombstoneSweepFreq time.Duration `name:"tombstone-sweep-freq"`
|
||||
|
||||
UserMaxSize int `name:"user-max-size"`
|
||||
UserTTL time.Duration `name:"user-ttl"`
|
||||
UserSweepFreq time.Duration `name:"user-sweep-freq"`
|
||||
}
|
||||
|
||||
// MarshalMap will marshal current Configuration into a map structure (useful for JSON/TOML/YAML).
|
||||
func (cfg *Configuration) MarshalMap() (map[string]interface{}, error) {
|
||||
var dst map[string]interface{}
|
||||
dec, _ := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
||||
|
Reference in New Issue
Block a user