diff options
Diffstat (limited to 'internal/cache')
-rw-r--r-- | internal/cache/cache.go | 2 | ||||
-rw-r--r-- | internal/cache/db.go | 32 | ||||
-rw-r--r-- | internal/cache/invalidate.go | 4 | ||||
-rw-r--r-- | internal/cache/size.go | 13 |
4 files changed, 51 insertions, 0 deletions
diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 9b70a565c..e2fe43a1f 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -75,6 +75,7 @@ func (c *Caches) Init() { c.initMarker() c.initMedia() c.initMention() + c.initMove() c.initNotification() c.initPoll() c.initPollVote() @@ -135,6 +136,7 @@ func (c *Caches) Sweep(threshold float64) { c.GTS.Marker.Trim(threshold) c.GTS.Media.Trim(threshold) c.GTS.Mention.Trim(threshold) + c.GTS.Move.Trim(threshold) c.GTS.Notification.Trim(threshold) c.GTS.Poll.Trim(threshold) c.GTS.Report.Trim(threshold) diff --git a/internal/cache/db.go b/internal/cache/db.go index dc9e385cd..00dfe204a 100644 --- a/internal/cache/db.go +++ b/internal/cache/db.go @@ -117,6 +117,9 @@ type GTSCaches struct { // Mention provides access to the gtsmodel Mention database cache. Mention structr.Cache[*gtsmodel.Mention] + // Move provides access to the gtsmodel Move database cache. + Move structr.Cache[*gtsmodel.Move] + // Notification provides access to the gtsmodel Notification database cache. Notification structr.Cache[*gtsmodel.Notification] @@ -185,6 +188,8 @@ func (c *Caches) initAccount() { a2.AvatarMediaAttachment = nil a2.HeaderMediaAttachment = nil a2.Emojis = nil + a2.AlsoKnownAs = nil + a2.Move = nil return a2 } @@ -816,6 +821,33 @@ func (c *Caches) initMention() { }) } +func (c *Caches) initMove() { + // Calculate maximum cache size. + cap := calculateResultCacheMax( + sizeofMove(), // model in-mem size. + config.GetCacheMoveMemRatio(), + ) + + log.Infof(nil, "cache size = %d", cap) + + c.GTS.Move.Init(structr.Config[*gtsmodel.Move]{ + Indices: []structr.IndexConfig{ + {Fields: "ID"}, + {Fields: "URI"}, + {Fields: "OriginURI,TargetURI"}, + {Fields: "OriginURI", Multiple: true}, + {Fields: "TargetURI", Multiple: true}, + }, + MaxSize: cap, + IgnoreErr: ignoreErrors, + CopyValue: func(m1 *gtsmodel.Move) *gtsmodel.Move { + m2 := new(gtsmodel.Move) + *m2 = *m1 + return m2 + }, + }) +} + func (c *Caches) initNotification() { // Calculate maximum cache size. cap := calculateResultCacheMax( diff --git a/internal/cache/invalidate.go b/internal/cache/invalidate.go index e7dfa9e8a..a7c4a1552 100644 --- a/internal/cache/invalidate.go +++ b/internal/cache/invalidate.go @@ -54,6 +54,10 @@ func (c *Caches) OnInvalidateAccount(account *gtsmodel.Account) { // Invalidate this account's block lists. c.GTS.BlockIDs.Invalidate(account.ID) + + // Invalidate this account's Move(s). + c.GTS.Move.Invalidate("OriginURI", account.URI) + c.GTS.Move.Invalidate("TargetURI", account.URI) } func (c *Caches) OnInvalidateBlock(block *gtsmodel.Block) { diff --git a/internal/cache/size.go b/internal/cache/size.go index f9d88491d..b1c431c55 100644 --- a/internal/cache/size.go +++ b/internal/cache/size.go @@ -460,6 +460,19 @@ func sizeofMention() uintptr { })) } +func sizeofMove() uintptr { + return uintptr(size.Of(>smodel.Move{ + ID: exampleID, + CreatedAt: exampleTime, + UpdatedAt: exampleTime, + AttemptedAt: exampleTime, + SucceededAt: exampleTime, + OriginURI: exampleURI, + TargetURI: exampleURI, + URI: exampleURI, + })) +} + func sizeofNotification() uintptr { return uintptr(size.Of(>smodel.Notification{ ID: exampleID, |