From b22e213e15a7bc64773e626d76305bd860e6301c Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:18:57 +0100 Subject: [feature/chore] Add Move database functions + cache (#2647) * [feature/chore] Add Move database functions + cache * add move mem ratio to envparsing.sh * update comment --- internal/cache/db.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'internal/cache/db.go') 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( -- cgit v1.2.3