summaryrefslogtreecommitdiff
path: root/internal/cache/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cache/db.go')
-rw-r--r--internal/cache/db.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/internal/cache/db.go b/internal/cache/db.go
index 50acf00d1..4c063b06d 100644
--- a/internal/cache/db.go
+++ b/internal/cache/db.go
@@ -56,6 +56,12 @@ type GTSCaches struct {
// Client provides access to the gtsmodel Client database cache.
Client StructCache[*gtsmodel.Client]
+ // Conversation provides access to the gtsmodel Conversation database cache.
+ Conversation StructCache[*gtsmodel.Conversation]
+
+ // ConversationLastStatusIDs provides access to the conversation last status IDs database cache.
+ ConversationLastStatusIDs SliceCache[string]
+
// DomainAllow provides access to the domain allow database cache.
DomainAllow *domain.Cache
@@ -426,6 +432,52 @@ func (c *Caches) initClient() {
})
}
+func (c *Caches) initConversation() {
+ cap := calculateResultCacheMax(
+ sizeofConversation(), // model in-mem size.
+ config.GetCacheConversationMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ copyF := func(c1 *gtsmodel.Conversation) *gtsmodel.Conversation {
+ c2 := new(gtsmodel.Conversation)
+ *c2 = *c1
+
+ // Don't include ptr fields that
+ // will be populated separately.
+ // See internal/db/bundb/conversation.go.
+ c2.Account = nil
+ c2.OtherAccounts = nil
+ c2.LastStatus = nil
+
+ return c2
+ }
+
+ c.GTS.Conversation.Init(structr.CacheConfig[*gtsmodel.Conversation]{
+ Indices: []structr.IndexConfig{
+ {Fields: "ID"},
+ {Fields: "ThreadID,AccountID,OtherAccountsKey"},
+ {Fields: "AccountID,LastStatusID"},
+ {Fields: "AccountID", Multiple: true},
+ },
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: copyF,
+ Invalidate: c.OnInvalidateConversation,
+ })
+}
+
+func (c *Caches) initConversationLastStatusIDs() {
+ cap := calculateSliceCacheMax(
+ config.GetCacheConversationLastStatusIDsMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ c.GTS.ConversationLastStatusIDs.Init(0, cap)
+}
+
func (c *Caches) initDomainAllow() {
c.GTS.DomainAllow = new(domain.Cache)
}