diff options
author | 2024-06-06 10:44:43 +0000 | |
---|---|---|
committer | 2024-06-06 11:44:43 +0100 | |
commit | 5dcc954072ca0a27107ed3fdc6806986f61df7d0 (patch) | |
tree | 7a6380bf39e99dbcfee4fbe1434697706637d2bc /internal/cache/db.go | |
parent | [bugfix] Don't nil emojis + fields on blocked accounts (#2968) (diff) | |
download | gotosocial-5dcc954072ca0a27107ed3fdc6806986f61df7d0.tar.xz |
[feature] do not uncache status / emoji media if attached status is bookmarked (#2956)
* do not uncache status / emoji media if attached status is bookmarked
* add status bookmark and bookmark IDs caches
* update status bookmark tests
* move IsStatusBookmarkedBy() to StatusBookmark{} interface, rely on cache
* fix envparsing.sh test
Diffstat (limited to 'internal/cache/db.go')
-rw-r--r-- | internal/cache/db.go | 54 |
1 files changed, 54 insertions, 0 deletions
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( |