summaryrefslogtreecommitdiff
path: root/internal/cache/cache.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-11-08 14:32:17 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-08 14:32:17 +0000
commite9e5dc5a40926e5320cb131b035c46b1e1b0bd59 (patch)
tree52edc9fa5742f28e1e5223f51cda628ec1c35a24 /internal/cache/cache.go
parent[chore]: Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#2338) (diff)
downloadgotosocial-e9e5dc5a40926e5320cb131b035c46b1e1b0bd59.tar.xz
[feature] add support for polls + receiving federated status edits (#2330)
Diffstat (limited to 'internal/cache/cache.go')
-rw-r--r--internal/cache/cache.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/cache/cache.go b/internal/cache/cache.go
index 777088f07..dabf151ff 100644
--- a/internal/cache/cache.go
+++ b/internal/cache/cache.go
@@ -183,6 +183,22 @@ func (c *Caches) setuphooks() {
}
})
+ c.GTS.Poll().SetInvalidateCallback(func(poll *gtsmodel.Poll) {
+ // Invalidate all cached votes of this poll.
+ c.GTS.PollVote().Invalidate("PollID", poll.ID)
+
+ // Invalidate cache of poll vote IDs.
+ c.GTS.PollVoteIDs().Invalidate(poll.ID)
+ })
+
+ c.GTS.PollVote().SetInvalidateCallback(func(vote *gtsmodel.PollVote) {
+ // Invalidate cached poll (contains no. votes).
+ c.GTS.Poll().Invalidate("ID", vote.PollID)
+
+ // Invalidate cache of poll vote IDs.
+ c.GTS.PollVoteIDs().Invalidate(vote.PollID)
+ })
+
c.GTS.Status().SetInvalidateCallback(func(status *gtsmodel.Status) {
// Invalidate status ID cached visibility.
c.Visibility.Invalidate("ItemID", status.ID)
@@ -206,6 +222,11 @@ func (c *Caches) setuphooks() {
// Invalidate in reply to ID list of original status.
c.GTS.InReplyToIDs().Invalidate(status.InReplyToID)
}
+
+ if status.PollID != "" {
+ // Invalidate cache of attached poll ID.
+ c.GTS.Poll().Invalidate("ID", status.PollID)
+ }
})
c.GTS.StatusFave().SetInvalidateCallback(func(fave *gtsmodel.StatusFave) {
@@ -244,6 +265,7 @@ func (c *Caches) Sweep(threshold float64) {
c.GTS.Media().Trim(threshold)
c.GTS.Mention().Trim(threshold)
c.GTS.Notification().Trim(threshold)
+ c.GTS.Poll().Trim(threshold)
c.GTS.Report().Trim(threshold)
c.GTS.Status().Trim(threshold)
c.GTS.StatusFave().Trim(threshold)