summaryrefslogtreecommitdiff
path: root/internal/cache
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cache')
-rw-r--r--internal/cache/cache.go8
-rw-r--r--internal/cache/db.go54
-rw-r--r--internal/cache/invalidate.go5
-rw-r--r--internal/cache/size.go18
4 files changed, 82 insertions, 3 deletions
diff --git a/internal/cache/cache.go b/internal/cache/cache.go
index 2c15d836d..2af5e20ca 100644
--- a/internal/cache/cache.go
+++ b/internal/cache/cache.go
@@ -85,6 +85,8 @@ func (c *Caches) Init() {
c.initPollVoteIDs()
c.initReport()
c.initStatus()
+ c.initStatusBookmark()
+ c.initStatusBookmarkIDs()
c.initStatusFave()
c.initStatusFaveIDs()
c.initTag()
@@ -101,7 +103,7 @@ func (c *Caches) Init() {
func (c *Caches) Start() {
log.Infof(nil, "start: %p", c)
- tryUntil("starting *gtsmodel.Webfinger cache", 5, func() bool {
+ tryUntil("starting webfinger cache", 5, func() bool {
return c.GTS.Webfinger.Start(5 * time.Minute)
})
}
@@ -111,7 +113,7 @@ func (c *Caches) Start() {
func (c *Caches) Stop() {
log.Infof(nil, "stop: %p", c)
- tryUntil("stopping *gtsmodel.Webfinger cache", 5, c.GTS.Webfinger.Stop)
+ tryUntil("stopping webfinger cache", 5, c.GTS.Webfinger.Stop)
}
// Sweep will sweep all the available caches to ensure none
@@ -153,6 +155,8 @@ func (c *Caches) Sweep(threshold float64) {
c.GTS.PollVoteIDs.Trim(threshold)
c.GTS.Report.Trim(threshold)
c.GTS.Status.Trim(threshold)
+ c.GTS.StatusBookmark.Trim(threshold)
+ c.GTS.StatusBookmarkIDs.Trim(threshold)
c.GTS.StatusFave.Trim(threshold)
c.GTS.StatusFaveIDs.Trim(threshold)
c.GTS.Tag.Trim(threshold)
diff --git a/internal/cache/db.go b/internal/cache/db.go
index 8a113bd30..a5325f6ef 100644
--- a/internal/cache/db.go
+++ b/internal/cache/db.go
@@ -139,6 +139,12 @@ type GTSCaches struct {
// Status provides access to the gtsmodel Status database cache.
Status StructCache[*gtsmodel.Status]
+ // StatusBookmark ...
+ StatusBookmark StructCache[*gtsmodel.StatusBookmark]
+
+ // StatusBookmarkIDs ...
+ StatusBookmarkIDs SliceCache[string]
+
// StatusFave provides access to the gtsmodel StatusFave database cache.
StatusFave StructCache[*gtsmodel.StatusFave]
@@ -1102,6 +1108,54 @@ func (c *Caches) initStatus() {
})
}
+func (c *Caches) initStatusBookmark() {
+ // Calculate maximum cache size.
+ cap := calculateResultCacheMax(
+ sizeofStatusBookmark(), // model in-mem size.
+ config.GetCacheStatusBookmarkMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ copyF := func(s1 *gtsmodel.StatusBookmark) *gtsmodel.StatusBookmark {
+ s2 := new(gtsmodel.StatusBookmark)
+ *s2 = *s1
+
+ // Don't include ptr fields that
+ // will be populated separately.
+ s2.Account = nil
+ s2.TargetAccount = nil
+ s2.Status = nil
+
+ return s2
+ }
+
+ c.GTS.StatusBookmark.Init(structr.CacheConfig[*gtsmodel.StatusBookmark]{
+ Indices: []structr.IndexConfig{
+ {Fields: "ID"},
+ {Fields: "AccountID,StatusID"},
+ {Fields: "AccountID", Multiple: true},
+ {Fields: "TargetAccountID", Multiple: true},
+ {Fields: "StatusID", Multiple: true},
+ },
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: copyF,
+ Invalidate: c.OnInvalidateStatusBookmark,
+ })
+}
+
+func (c *Caches) initStatusBookmarkIDs() {
+ // Calculate maximum cache size.
+ cap := calculateSliceCacheMax(
+ config.GetCacheStatusBookmarkIDsMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ c.GTS.StatusBookmarkIDs.Init(0, cap)
+}
+
func (c *Caches) initStatusFave() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(
diff --git a/internal/cache/invalidate.go b/internal/cache/invalidate.go
index 01d332d40..9c626d7a9 100644
--- a/internal/cache/invalidate.go
+++ b/internal/cache/invalidate.go
@@ -198,6 +198,11 @@ func (c *Caches) OnInvalidateStatus(status *gtsmodel.Status) {
}
}
+func (c *Caches) OnInvalidateStatusBookmark(bookmark *gtsmodel.StatusBookmark) {
+ // Invalidate status bookmark ID list for this status.
+ c.GTS.StatusBookmarkIDs.Invalidate(bookmark.StatusID)
+}
+
func (c *Caches) OnInvalidateStatusFave(fave *gtsmodel.StatusFave) {
// Invalidate status fave ID list for this status.
c.GTS.StatusFaveIDs.Invalidate(fave.StatusID)
diff --git a/internal/cache/size.go b/internal/cache/size.go
index 758d191be..e205bf023 100644
--- a/internal/cache/size.go
+++ b/internal/cache/size.go
@@ -201,6 +201,8 @@ func totalOfRatios() float64 {
config.GetCachePollVoteMemRatio() +
config.GetCacheReportMemRatio() +
config.GetCacheStatusMemRatio() +
+ config.GetCacheStatusBookmarkMemRatio() +
+ config.GetCacheStatusBookmarkIDsMemRatio() +
config.GetCacheStatusFaveMemRatio() +
config.GetCacheStatusFaveIDsMemRatio() +
config.GetCacheTagMemRatio() +
@@ -566,7 +568,7 @@ func sizeofReport() uintptr {
func sizeofStatus() uintptr {
return uintptr(size.Of(&gtsmodel.Status{
- ID: exampleURI,
+ ID: exampleID,
URI: exampleURI,
URL: exampleURI,
Content: exampleText,
@@ -599,6 +601,20 @@ func sizeofStatus() uintptr {
}))
}
+func sizeofStatusBookmark() uintptr {
+ return uintptr(size.Of(&gtsmodel.StatusBookmark{
+ ID: exampleID,
+ AccountID: exampleID,
+ Account: nil,
+ TargetAccountID: exampleID,
+ TargetAccount: nil,
+ StatusID: exampleID,
+ Status: nil,
+ CreatedAt: exampleTime,
+ UpdatedAt: exampleTime,
+ }))
+}
+
func sizeofStatusFave() uintptr {
return uintptr(size.Of(&gtsmodel.StatusFave{
ID: exampleID,