implement report cache + config changes

This commit is contained in:
tsmethurst 2023-01-06 13:49:24 +01:00
parent 838dfbead6
commit c1854a7dcc
5 changed files with 112 additions and 0 deletions

View file

@ -207,6 +207,10 @@ cache:
notification-ttl: "5m"
notification-sweep-freq: "10s"
report-max-size: 100
report-ttl: "5m"
report-sweep-freq: "10s"
status-max-size: 500
status-ttl: "5m"
status-sweep-freq: "10s"

25
internal/cache/gts.go vendored
View file

@ -57,6 +57,9 @@ type GTSCaches interface {
// Notification provides access to the gtsmodel Notification database cache.
Notification() *result.Cache[*gtsmodel.Notification]
// Report provides access to the gtsmodel Report database cache.
Report() *result.Cache[*gtsmodel.Report]
// Status provides access to the gtsmodel Status database cache.
Status() *result.Cache[*gtsmodel.Status]
@ -80,6 +83,7 @@ type gtsCaches struct {
emojiCategory *result.Cache[*gtsmodel.EmojiCategory]
mention *result.Cache[*gtsmodel.Mention]
notification *result.Cache[*gtsmodel.Notification]
report *result.Cache[*gtsmodel.Report]
status *result.Cache[*gtsmodel.Status]
tombstone *result.Cache[*gtsmodel.Tombstone]
user *result.Cache[*gtsmodel.User]
@ -93,6 +97,7 @@ func (c *gtsCaches) Init() {
c.initEmojiCategory()
c.initMention()
c.initNotification()
c.initReport()
c.initStatus()
c.initTombstone()
c.initUser()
@ -120,6 +125,9 @@ func (c *gtsCaches) Start() {
tryUntil("starting gtsmodel.Notification cache", 5, func() bool {
return c.notification.Start(config.GetCacheGTSNotificationSweepFreq())
})
tryUntil("starting gtsmodel.Report cache", 5, func() bool {
return c.report.Start(config.GetCacheGTSReportSweepFreq())
})
tryUntil("starting gtsmodel.Status cache", 5, func() bool {
return c.status.Start(config.GetCacheGTSStatusSweepFreq())
})
@ -139,6 +147,7 @@ func (c *gtsCaches) Stop() {
tryUntil("stopping gtsmodel.EmojiCategory cache", 5, c.emojiCategory.Stop)
tryUntil("stopping gtsmodel.Mention cache", 5, c.mention.Stop)
tryUntil("stopping gtsmodel.Notification cache", 5, c.notification.Stop)
tryUntil("stopping gtsmodel.Report cache", 5, c.report.Stop)
tryUntil("stopping gtsmodel.Status cache", 5, c.status.Stop)
tryUntil("stopping gtsmodel.Tombstone cache", 5, c.tombstone.Stop)
tryUntil("stopping gtsmodel.User cache", 5, c.user.Stop)
@ -172,6 +181,10 @@ func (c *gtsCaches) Notification() *result.Cache[*gtsmodel.Notification] {
return c.notification
}
func (c *gtsCaches) Report() *result.Cache[*gtsmodel.Report] {
return c.report
}
func (c *gtsCaches) Status() *result.Cache[*gtsmodel.Status] {
return c.status
}
@ -267,6 +280,18 @@ func (c *gtsCaches) initNotification() {
c.notification.SetTTL(config.GetCacheGTSNotificationTTL(), true)
}
func (c *gtsCaches) initReport() {
c.report = result.New([]result.Lookup{
{Name: "ID"},
{Name: "URI"},
}, func(r1 *gtsmodel.Report) *gtsmodel.Report {
r2 := new(gtsmodel.Report)
*r2 = *r1
return r2
}, config.GetCacheGTSReportMaxSize())
c.report.SetTTL(config.GetCacheGTSReportTTL(), true)
}
func (c *gtsCaches) initStatus() {
c.status = result.New([]result.Lookup{
{Name: "ID"},

View file

@ -175,6 +175,10 @@ type GTSCacheConfiguration struct {
NotificationTTL time.Duration `name:"notification-ttl"`
NotificationSweepFreq time.Duration `name:"notification-sweep-freq"`
ReportMaxSize int `name:"report-max-size"`
ReportTTL time.Duration `name:"report-ttl"`
ReportSweepFreq time.Duration `name:"report-sweep-freq"`
StatusMaxSize int `name:"status-max-size"`
StatusTTL time.Duration `name:"status-ttl"`
StatusSweepFreq time.Duration `name:"status-sweep-freq"`

View file

@ -138,6 +138,10 @@ var Defaults = Configuration{
NotificationTTL: time.Minute * 5,
NotificationSweepFreq: time.Second * 10,
ReportMaxSize: 100,
ReportTTL: time.Minute * 5,
ReportSweepFreq: time.Second * 10,
StatusMaxSize: 500,
StatusTTL: time.Minute * 5,
StatusSweepFreq: time.Second * 10,

View file

@ -2378,6 +2378,81 @@ func GetCacheGTSNotificationSweepFreq() time.Duration {
// SetCacheGTSNotificationSweepFreq safely sets the value for global configuration 'Cache.GTS.NotificationSweepFreq' field
func SetCacheGTSNotificationSweepFreq(v time.Duration) { global.SetCacheGTSNotificationSweepFreq(v) }
// GetCacheGTSReportMaxSize safely fetches the Configuration value for state's 'Cache.GTS.ReportMaxSize' field
func (st *ConfigState) GetCacheGTSReportMaxSize() (v int) {
st.mutex.Lock()
v = st.config.Cache.GTS.ReportMaxSize
st.mutex.Unlock()
return
}
// SetCacheGTSReportMaxSize safely sets the Configuration value for state's 'Cache.GTS.ReportMaxSize' field
func (st *ConfigState) SetCacheGTSReportMaxSize(v int) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.config.Cache.GTS.ReportMaxSize = v
st.reloadToViper()
}
// CacheGTSReportMaxSizeFlag returns the flag name for the 'Cache.GTS.ReportMaxSize' field
func CacheGTSReportMaxSizeFlag() string { return "cache-gts-report-max-size" }
// GetCacheGTSReportMaxSize safely fetches the value for global configuration 'Cache.GTS.ReportMaxSize' field
func GetCacheGTSReportMaxSize() int { return global.GetCacheGTSReportMaxSize() }
// SetCacheGTSReportMaxSize safely sets the value for global configuration 'Cache.GTS.ReportMaxSize' field
func SetCacheGTSReportMaxSize(v int) { global.SetCacheGTSReportMaxSize(v) }
// GetCacheGTSReportTTL safely fetches the Configuration value for state's 'Cache.GTS.ReportTTL' field
func (st *ConfigState) GetCacheGTSReportTTL() (v time.Duration) {
st.mutex.Lock()
v = st.config.Cache.GTS.ReportTTL
st.mutex.Unlock()
return
}
// SetCacheGTSReportTTL safely sets the Configuration value for state's 'Cache.GTS.ReportTTL' field
func (st *ConfigState) SetCacheGTSReportTTL(v time.Duration) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.config.Cache.GTS.ReportTTL = v
st.reloadToViper()
}
// CacheGTSReportTTLFlag returns the flag name for the 'Cache.GTS.ReportTTL' field
func CacheGTSReportTTLFlag() string { return "cache-gts-report-ttl" }
// GetCacheGTSReportTTL safely fetches the value for global configuration 'Cache.GTS.ReportTTL' field
func GetCacheGTSReportTTL() time.Duration { return global.GetCacheGTSReportTTL() }
// SetCacheGTSReportTTL safely sets the value for global configuration 'Cache.GTS.ReportTTL' field
func SetCacheGTSReportTTL(v time.Duration) { global.SetCacheGTSReportTTL(v) }
// GetCacheGTSReportSweepFreq safely fetches the Configuration value for state's 'Cache.GTS.ReportSweepFreq' field
func (st *ConfigState) GetCacheGTSReportSweepFreq() (v time.Duration) {
st.mutex.Lock()
v = st.config.Cache.GTS.ReportSweepFreq
st.mutex.Unlock()
return
}
// SetCacheGTSReportSweepFreq safely sets the Configuration value for state's 'Cache.GTS.ReportSweepFreq' field
func (st *ConfigState) SetCacheGTSReportSweepFreq(v time.Duration) {
st.mutex.Lock()
defer st.mutex.Unlock()
st.config.Cache.GTS.ReportSweepFreq = v
st.reloadToViper()
}
// CacheGTSReportSweepFreqFlag returns the flag name for the 'Cache.GTS.ReportSweepFreq' field
func CacheGTSReportSweepFreqFlag() string { return "cache-gts-report-sweep-freq" }
// GetCacheGTSReportSweepFreq safely fetches the value for global configuration 'Cache.GTS.ReportSweepFreq' field
func GetCacheGTSReportSweepFreq() time.Duration { return global.GetCacheGTSReportSweepFreq() }
// SetCacheGTSReportSweepFreq safely sets the value for global configuration 'Cache.GTS.ReportSweepFreq' field
func SetCacheGTSReportSweepFreq(v time.Duration) { global.SetCacheGTSReportSweepFreq(v) }
// GetCacheGTSStatusMaxSize safely fetches the Configuration value for state's 'Cache.GTS.StatusMaxSize' field
func (st *ConfigState) GetCacheGTSStatusMaxSize() (v int) {
st.mutex.Lock()