summaryrefslogtreecommitdiff
path: root/internal/cache
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-09-10 14:34:49 +0200
committerLibravatar GitHub <noreply@github.com>2024-09-10 12:34:49 +0000
commit307d98e3862b6e867eea524b81d5428b03e6607c (patch)
treeb990378c5452f5779b85bd0d769db77a78f93600 /internal/cache
parent[chore] status dereferencing improvements (#3255) (diff)
downloadgotosocial-307d98e3862b6e867eea524b81d5428b03e6607c.tar.xz
[feature] Process `Reject` of interaction via fedi API, put rejected statuses in the "sin bin" 😈 (#3271)
* [feature] Process `Reject` of interaction via fedi API, put rejected statuses in the "sin bin" * update test * move nil check back to `rejectStatusIRI`
Diffstat (limited to 'internal/cache')
-rw-r--r--internal/cache/cache.go2
-rw-r--r--internal/cache/db.go29
-rw-r--r--internal/cache/size.go23
3 files changed, 54 insertions, 0 deletions
diff --git a/internal/cache/cache.go b/internal/cache/cache.go
index f1c382d11..5554445b2 100644
--- a/internal/cache/cache.go
+++ b/internal/cache/cache.go
@@ -93,6 +93,7 @@ func (c *Caches) Init() {
c.initPollVote()
c.initPollVoteIDs()
c.initReport()
+ c.initSinBinStatus()
c.initStatus()
c.initStatusBookmark()
c.initStatusBookmarkIDs()
@@ -170,6 +171,7 @@ func (c *Caches) Sweep(threshold float64) {
c.DB.PollVote.Trim(threshold)
c.DB.PollVoteIDs.Trim(threshold)
c.DB.Report.Trim(threshold)
+ c.DB.SinBinStatus.Trim(threshold)
c.DB.Status.Trim(threshold)
c.DB.StatusBookmark.Trim(threshold)
c.DB.StatusBookmarkIDs.Trim(threshold)
diff --git a/internal/cache/db.go b/internal/cache/db.go
index 5e86c92a2..7f54ee8c5 100644
--- a/internal/cache/db.go
+++ b/internal/cache/db.go
@@ -145,6 +145,9 @@ type DBCaches struct {
// Report provides access to the gtsmodel Report database cache.
Report StructCache[*gtsmodel.Report]
+ // SinBinStatus provides access to the gtsmodel SinBinStatus database cache.
+ SinBinStatus StructCache[*gtsmodel.SinBinStatus]
+
// Status provides access to the gtsmodel Status database cache.
Status StructCache[*gtsmodel.Status]
@@ -1170,6 +1173,32 @@ func (c *Caches) initReport() {
})
}
+func (c *Caches) initSinBinStatus() {
+ // Calculate maximum cache size.
+ cap := calculateResultCacheMax(
+ sizeofSinBinStatus(), // model in-mem size.
+ config.GetCacheSinBinStatusMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ copyF := func(s1 *gtsmodel.SinBinStatus) *gtsmodel.SinBinStatus {
+ s2 := new(gtsmodel.SinBinStatus)
+ *s2 = *s1
+ return s2
+ }
+
+ c.DB.SinBinStatus.Init(structr.CacheConfig[*gtsmodel.SinBinStatus]{
+ Indices: []structr.IndexConfig{
+ {Fields: "ID"},
+ {Fields: "URI"},
+ },
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: copyF,
+ })
+}
+
func (c *Caches) initStatus() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(
diff --git a/internal/cache/size.go b/internal/cache/size.go
index 29ab77fbf..49c2f4318 100644
--- a/internal/cache/size.go
+++ b/internal/cache/size.go
@@ -593,6 +593,29 @@ func sizeofReport() uintptr {
}))
}
+func sizeofSinBinStatus() uintptr {
+ return uintptr(size.Of(&gtsmodel.SinBinStatus{
+ ID: exampleID,
+ CreatedAt: exampleTime,
+ UpdatedAt: exampleTime,
+ URI: exampleURI,
+ URL: exampleURI,
+ Domain: exampleURI,
+ AccountURI: exampleURI,
+ InReplyToURI: exampleURI,
+ Content: exampleText,
+ AttachmentLinks: []string{exampleURI, exampleURI},
+ MentionTargetURIs: []string{exampleURI},
+ EmojiLinks: []string{exampleURI},
+ PollOptions: []string{exampleTextSmall, exampleTextSmall, exampleTextSmall, exampleTextSmall},
+ ContentWarning: exampleTextSmall,
+ Visibility: gtsmodel.VisibilityPublic,
+ Sensitive: util.Ptr(false),
+ Language: "en",
+ ActivityStreamsType: ap.ObjectNote,
+ }))
+}
+
func sizeofStatus() uintptr {
return uintptr(size.Of(&gtsmodel.Status{
ID: exampleID,