summaryrefslogtreecommitdiff
path: root/internal/cache/cache.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-09-16 14:00:23 +0200
committerLibravatar GitHub <noreply@github.com>2024-09-16 14:00:23 +0200
commitefd1a4f717afa83d3d3609f0d70e4da151a8dc9b (patch)
tree246ae4c12f86f8866e5299ae39ba5c1feba0bce4 /internal/cache/cache.go
parent[bugfix/chore] Always set the status sensitive if media + content-warning pre... (diff)
downloadgotosocial-efd1a4f717afa83d3d3609f0d70e4da151a8dc9b.tar.xz
[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
Diffstat (limited to 'internal/cache/cache.go')
-rw-r--r--internal/cache/cache.go20
1 files changed, 20 insertions, 0 deletions
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,
+ )
+}