From efd1a4f717afa83d3d3609f0d70e4da151a8dc9b Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 16 Sep 2024 14:00:23 +0200 Subject: [bugfix] Use better plaintext representation of status for filtering (#3301) * [bugfix] Use better plaintext representation of status for filtering * add new deps to readme * lint * update tests * update regexes * address review comments * remove now unused xxhash * whoops, wrong logger * Merge branch 'main' into status_filtering_bugfix * put cache in caches struct * pain --- internal/cache/cache.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'internal/cache') diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 5554445b2..8291dec5a 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -47,6 +47,11 @@ type Caches struct { // Webfinger provides access to the webfinger URL cache. Webfinger *ttl.Cache[string, string] // TTL=24hr, sweep=5min + // TTL cache of statuses -> filterable text fields. + // To ensure up-to-date fields, cache is keyed as: + // `[status.ID][status.UpdatedAt.Unix()]` + StatusesFilterableFields *ttl.Cache[string, []string] + // prevent pass-by-value. _ nocopy } @@ -109,6 +114,7 @@ func (c *Caches) Init() { c.initUserMuteIDs() c.initWebfinger() c.initVisibility() + c.initStatusesFilterableFields() } // Start will start any caches that require a background @@ -119,6 +125,10 @@ func (c *Caches) Start() { tryUntil("starting webfinger cache", 5, func() bool { return c.Webfinger.Start(5 * time.Minute) }) + + tryUntil("starting statusesFilterableFields cache", 5, func() bool { + return c.StatusesFilterableFields.Start(5 * time.Minute) + }) } // Stop will stop any caches that require a background @@ -127,6 +137,7 @@ func (c *Caches) Stop() { log.Infof(nil, "stop: %p", c) tryUntil("stopping webfinger cache", 5, c.Webfinger.Stop) + tryUntil("stopping statusesFilterableFields cache", 5, c.StatusesFilterableFields.Stop) } // Sweep will sweep all the available caches to ensure none @@ -204,3 +215,12 @@ func (c *Caches) initWebfinger() { 24*time.Hour, ) } + +func (c *Caches) initStatusesFilterableFields() { + c.StatusesFilterableFields = new(ttl.Cache[string, []string]) + c.StatusesFilterableFields.Init( + 0, + 512, + 1*time.Hour, + ) +} -- cgit v1.2.3