diff options
Diffstat (limited to 'internal/cache/db.go')
-rw-r--r-- | internal/cache/db.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/cache/db.go b/internal/cache/db.go index d0fe77649..50acf00d1 100644 --- a/internal/cache/db.go +++ b/internal/cache/db.go @@ -100,6 +100,9 @@ type GTSCaches struct { // Instance provides access to the gtsmodel Instance database cache. Instance StructCache[*gtsmodel.Instance] + // InteractionApproval provides access to the gtsmodel InteractionApproval database cache. + InteractionApproval StructCache[*gtsmodel.InteractionApproval] + // InReplyToIDs provides access to the status in reply to IDs list database cache. InReplyToIDs SliceCache[string] @@ -737,6 +740,39 @@ func (c *Caches) initInstance() { }) } +func (c *Caches) initInteractionApproval() { + // Calculate maximum cache size. + cap := calculateResultCacheMax( + sizeofInteractionApproval(), + config.GetCacheInteractionApprovalMemRatio(), + ) + + log.Infof(nil, "cache size = %d", cap) + + copyF := func(i1 *gtsmodel.InteractionApproval) *gtsmodel.InteractionApproval { + i2 := new(gtsmodel.InteractionApproval) + *i2 = *i1 + + // Don't include ptr fields that + // will be populated separately. + // See internal/db/bundb/interaction.go. + i2.Account = nil + i2.InteractingAccount = nil + + return i2 + } + + c.GTS.InteractionApproval.Init(structr.CacheConfig[*gtsmodel.InteractionApproval]{ + Indices: []structr.IndexConfig{ + {Fields: "ID"}, + {Fields: "URI"}, + }, + MaxSize: cap, + IgnoreErr: ignoreErrors, + Copy: copyF, + }) +} + func (c *Caches) initList() { // Calculate maximum cache size. cap := calculateResultCacheMax( @@ -1188,6 +1224,7 @@ func (c *Caches) initStatusFave() { c.GTS.StatusFave.Init(structr.CacheConfig[*gtsmodel.StatusFave]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, + {Fields: "URI"}, {Fields: "AccountID,StatusID"}, {Fields: "StatusID", Multiple: true}, }, |