diff options
Diffstat (limited to 'internal/cache')
-rw-r--r-- | internal/cache/cache.go | 118 | ||||
-rw-r--r-- | internal/cache/db.go | 122 | ||||
-rw-r--r-- | internal/cache/invalidate.go | 64 |
3 files changed, 151 insertions, 153 deletions
diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 8b0c04ea4..8187ba419 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -20,15 +20,17 @@ package cache import ( "time" + "codeberg.org/gruf/go-cache/v3/ttl" "github.com/superseriousbusiness/gotosocial/internal/cache/headerfilter" + "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/log" ) type Caches struct { - // GTS provides access to the collection of + // DB provides access to the collection of // gtsmodel object caches. (used by the database). - GTS GTSCaches + DB DBCaches // AllowHeaderFilters provides access to // the allow []headerfilter.Filter cache. @@ -42,6 +44,9 @@ type Caches struct { // cache. (used by the visibility filter). Visibility VisibilityCache + // Webfinger provides access to the webfinger URL cache. + Webfinger *ttl.Cache[string, string] // TTL=24hr, sweep=5min + // prevent pass-by-value. _ nocopy } @@ -109,7 +114,7 @@ func (c *Caches) Start() { log.Infof(nil, "start: %p", c) tryUntil("starting webfinger cache", 5, func() bool { - return c.GTS.Webfinger.Start(5 * time.Minute) + return c.Webfinger.Start(5 * time.Minute) }) } @@ -118,7 +123,7 @@ func (c *Caches) Start() { func (c *Caches) Stop() { log.Infof(nil, "stop: %p", c) - tryUntil("stopping webfinger cache", 5, c.GTS.Webfinger.Stop) + tryUntil("stopping webfinger cache", 5, c.Webfinger.Stop) } // Sweep will sweep all the available caches to ensure none @@ -128,49 +133,66 @@ func (c *Caches) Stop() { // require an eviction on every single write, which adds // significant overhead to all cache writes. func (c *Caches) Sweep(threshold float64) { - c.GTS.Account.Trim(threshold) - c.GTS.AccountNote.Trim(threshold) - c.GTS.AccountSettings.Trim(threshold) - c.GTS.AccountStats.Trim(threshold) - c.GTS.Application.Trim(threshold) - c.GTS.Block.Trim(threshold) - c.GTS.BlockIDs.Trim(threshold) - c.GTS.BoostOfIDs.Trim(threshold) - c.GTS.Client.Trim(threshold) - c.GTS.Emoji.Trim(threshold) - c.GTS.EmojiCategory.Trim(threshold) - c.GTS.Filter.Trim(threshold) - c.GTS.FilterKeyword.Trim(threshold) - c.GTS.FilterStatus.Trim(threshold) - c.GTS.Follow.Trim(threshold) - c.GTS.FollowIDs.Trim(threshold) - c.GTS.FollowRequest.Trim(threshold) - c.GTS.FollowRequestIDs.Trim(threshold) - c.GTS.InReplyToIDs.Trim(threshold) - c.GTS.Instance.Trim(threshold) - c.GTS.InteractionApproval.Trim(threshold) - c.GTS.List.Trim(threshold) - c.GTS.ListEntry.Trim(threshold) - 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.PollVote.Trim(threshold) - c.GTS.PollVoteIDs.Trim(threshold) - c.GTS.Report.Trim(threshold) - c.GTS.Status.Trim(threshold) - c.GTS.StatusBookmark.Trim(threshold) - c.GTS.StatusBookmarkIDs.Trim(threshold) - c.GTS.StatusFave.Trim(threshold) - c.GTS.StatusFaveIDs.Trim(threshold) - c.GTS.Tag.Trim(threshold) - c.GTS.ThreadMute.Trim(threshold) - c.GTS.Token.Trim(threshold) - c.GTS.Tombstone.Trim(threshold) - c.GTS.User.Trim(threshold) - c.GTS.UserMute.Trim(threshold) - c.GTS.UserMuteIDs.Trim(threshold) + c.DB.Account.Trim(threshold) + c.DB.AccountNote.Trim(threshold) + c.DB.AccountSettings.Trim(threshold) + c.DB.AccountStats.Trim(threshold) + c.DB.Application.Trim(threshold) + c.DB.Block.Trim(threshold) + c.DB.BlockIDs.Trim(threshold) + c.DB.BoostOfIDs.Trim(threshold) + c.DB.Client.Trim(threshold) + c.DB.Emoji.Trim(threshold) + c.DB.EmojiCategory.Trim(threshold) + c.DB.Filter.Trim(threshold) + c.DB.FilterKeyword.Trim(threshold) + c.DB.FilterStatus.Trim(threshold) + c.DB.Follow.Trim(threshold) + c.DB.FollowIDs.Trim(threshold) + c.DB.FollowRequest.Trim(threshold) + c.DB.FollowRequestIDs.Trim(threshold) + c.DB.InReplyToIDs.Trim(threshold) + c.DB.Instance.Trim(threshold) + c.DB.InteractionApproval.Trim(threshold) + c.DB.List.Trim(threshold) + c.DB.ListEntry.Trim(threshold) + c.DB.Marker.Trim(threshold) + c.DB.Media.Trim(threshold) + c.DB.Mention.Trim(threshold) + c.DB.Move.Trim(threshold) + c.DB.Notification.Trim(threshold) + c.DB.Poll.Trim(threshold) + c.DB.PollVote.Trim(threshold) + c.DB.PollVoteIDs.Trim(threshold) + c.DB.Report.Trim(threshold) + c.DB.Status.Trim(threshold) + c.DB.StatusBookmark.Trim(threshold) + c.DB.StatusBookmarkIDs.Trim(threshold) + c.DB.StatusFave.Trim(threshold) + c.DB.StatusFaveIDs.Trim(threshold) + c.DB.Tag.Trim(threshold) + c.DB.ThreadMute.Trim(threshold) + c.DB.Token.Trim(threshold) + c.DB.Tombstone.Trim(threshold) + c.DB.User.Trim(threshold) + c.DB.UserMute.Trim(threshold) + c.DB.UserMuteIDs.Trim(threshold) c.Visibility.Trim(threshold) } + +func (c *Caches) initWebfinger() { + // Calculate maximum cache size. + cap := calculateCacheMax( + sizeofURIStr, sizeofURIStr, + config.GetCacheWebfingerMemRatio(), + ) + + log.Infof(nil, "cache size = %d", cap) + + c.Webfinger = new(ttl.Cache[string, string]) + c.Webfinger.Init( + 0, + cap, + 24*time.Hour, + ) +} diff --git a/internal/cache/db.go b/internal/cache/db.go index 4c063b06d..16e1d286a 100644 --- a/internal/cache/db.go +++ b/internal/cache/db.go @@ -18,9 +18,6 @@ package cache import ( - "time" - - "codeberg.org/gruf/go-cache/v3/ttl" "codeberg.org/gruf/go-structr" "github.com/superseriousbusiness/gotosocial/internal/cache/domain" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -28,7 +25,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/log" ) -type GTSCaches struct { +type DBCaches struct { // Account provides access to the gtsmodel Account database cache. Account StructCache[*gtsmodel.Account] @@ -180,10 +177,6 @@ type GTSCaches struct { // UserMuteIDs provides access to the user mute IDs database cache. UserMuteIDs SliceCache[string] - - // Webfinger provides access to the webfinger URL cache. - // TODO: move out of GTS caches since unrelated to DB. - Webfinger *ttl.Cache[string, string] // TTL=24hr, sweep=5min } // NOTE: @@ -222,7 +215,7 @@ func (c *Caches) initAccount() { return a2 } - c.GTS.Account.Init(structr.CacheConfig[*gtsmodel.Account]{ + c.DB.Account.Init(structr.CacheConfig[*gtsmodel.Account]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -263,7 +256,7 @@ func (c *Caches) initAccountNote() { return n2 } - c.GTS.AccountNote.Init(structr.CacheConfig[*gtsmodel.AccountNote]{ + c.DB.AccountNote.Init(structr.CacheConfig[*gtsmodel.AccountNote]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "AccountID,TargetAccountID"}, @@ -283,7 +276,7 @@ func (c *Caches) initAccountSettings() { log.Infof(nil, "cache size = %d", cap) - c.GTS.AccountSettings.Init(structr.CacheConfig[*gtsmodel.AccountSettings]{ + c.DB.AccountSettings.Init(structr.CacheConfig[*gtsmodel.AccountSettings]{ Indices: []structr.IndexConfig{ {Fields: "AccountID"}, }, @@ -306,7 +299,7 @@ func (c *Caches) initAccountStats() { log.Infof(nil, "cache size = %d", cap) - c.GTS.AccountStats.Init(structr.CacheConfig[*gtsmodel.AccountStats]{ + c.DB.AccountStats.Init(structr.CacheConfig[*gtsmodel.AccountStats]{ Indices: []structr.IndexConfig{ {Fields: "AccountID"}, }, @@ -335,7 +328,7 @@ func (c *Caches) initApplication() { return a2 } - c.GTS.Application.Init(structr.CacheConfig[*gtsmodel.Application]{ + c.DB.Application.Init(structr.CacheConfig[*gtsmodel.Application]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "ClientID"}, @@ -369,7 +362,7 @@ func (c *Caches) initBlock() { return b2 } - c.GTS.Block.Init(structr.CacheConfig[*gtsmodel.Block]{ + c.DB.Block.Init(structr.CacheConfig[*gtsmodel.Block]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -392,7 +385,7 @@ func (c *Caches) initBlockIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.BlockIDs.Init(0, cap) + c.DB.BlockIDs.Init(0, cap) } func (c *Caches) initBoostOfIDs() { @@ -403,7 +396,7 @@ func (c *Caches) initBoostOfIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.BoostOfIDs.Init(0, cap) + c.DB.BoostOfIDs.Init(0, cap) } func (c *Caches) initClient() { @@ -421,7 +414,7 @@ func (c *Caches) initClient() { return c2 } - c.GTS.Client.Init(structr.CacheConfig[*gtsmodel.Client]{ + c.DB.Client.Init(structr.CacheConfig[*gtsmodel.Client]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, }, @@ -454,7 +447,7 @@ func (c *Caches) initConversation() { return c2 } - c.GTS.Conversation.Init(structr.CacheConfig[*gtsmodel.Conversation]{ + c.DB.Conversation.Init(structr.CacheConfig[*gtsmodel.Conversation]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "ThreadID,AccountID,OtherAccountsKey"}, @@ -475,15 +468,15 @@ func (c *Caches) initConversationLastStatusIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.ConversationLastStatusIDs.Init(0, cap) + c.DB.ConversationLastStatusIDs.Init(0, cap) } func (c *Caches) initDomainAllow() { - c.GTS.DomainAllow = new(domain.Cache) + c.DB.DomainAllow = new(domain.Cache) } func (c *Caches) initDomainBlock() { - c.GTS.DomainBlock = new(domain.Cache) + c.DB.DomainBlock = new(domain.Cache) } func (c *Caches) initEmoji() { @@ -507,7 +500,7 @@ func (c *Caches) initEmoji() { return e2 } - c.GTS.Emoji.Init(structr.CacheConfig[*gtsmodel.Emoji]{ + c.DB.Emoji.Init(structr.CacheConfig[*gtsmodel.Emoji]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -536,7 +529,7 @@ func (c *Caches) initEmojiCategory() { return c2 } - c.GTS.EmojiCategory.Init(structr.CacheConfig[*gtsmodel.EmojiCategory]{ + c.DB.EmojiCategory.Init(structr.CacheConfig[*gtsmodel.EmojiCategory]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "Name"}, @@ -570,7 +563,7 @@ func (c *Caches) initFilter() { return filter2 } - c.GTS.Filter.Init(structr.CacheConfig[*gtsmodel.Filter]{ + c.DB.Filter.Init(structr.CacheConfig[*gtsmodel.Filter]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "AccountID", Multiple: true}, @@ -607,7 +600,7 @@ func (c *Caches) initFilterKeyword() { return filterKeyword2 } - c.GTS.FilterKeyword.Init(structr.CacheConfig[*gtsmodel.FilterKeyword]{ + c.DB.FilterKeyword.Init(structr.CacheConfig[*gtsmodel.FilterKeyword]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "AccountID", Multiple: true}, @@ -640,7 +633,7 @@ func (c *Caches) initFilterStatus() { return filterStatus2 } - c.GTS.FilterStatus.Init(structr.CacheConfig[*gtsmodel.FilterStatus]{ + c.DB.FilterStatus.Init(structr.CacheConfig[*gtsmodel.FilterStatus]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "AccountID", Multiple: true}, @@ -674,7 +667,7 @@ func (c *Caches) initFollow() { return f2 } - c.GTS.Follow.Init(structr.CacheConfig[*gtsmodel.Follow]{ + c.DB.Follow.Init(structr.CacheConfig[*gtsmodel.Follow]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -697,7 +690,7 @@ func (c *Caches) initFollowIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.FollowIDs.Init(0, cap) + c.DB.FollowIDs.Init(0, cap) } func (c *Caches) initFollowRequest() { @@ -722,7 +715,7 @@ func (c *Caches) initFollowRequest() { return f2 } - c.GTS.FollowRequest.Init(structr.CacheConfig[*gtsmodel.FollowRequest]{ + c.DB.FollowRequest.Init(structr.CacheConfig[*gtsmodel.FollowRequest]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -745,7 +738,7 @@ func (c *Caches) initFollowRequestIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.FollowRequestIDs.Init(0, cap) + c.DB.FollowRequestIDs.Init(0, cap) } func (c *Caches) initInReplyToIDs() { @@ -756,7 +749,7 @@ func (c *Caches) initInReplyToIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.InReplyToIDs.Init(0, cap) + c.DB.InReplyToIDs.Init(0, cap) } func (c *Caches) initInstance() { @@ -781,7 +774,7 @@ func (c *Caches) initInstance() { return i2 } - c.GTS.Instance.Init(structr.CacheConfig[*gtsmodel.Instance]{ + c.DB.Instance.Init(structr.CacheConfig[*gtsmodel.Instance]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "Domain"}, @@ -814,7 +807,7 @@ func (c *Caches) initInteractionApproval() { return i2 } - c.GTS.InteractionApproval.Init(structr.CacheConfig[*gtsmodel.InteractionApproval]{ + c.DB.InteractionApproval.Init(structr.CacheConfig[*gtsmodel.InteractionApproval]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -847,7 +840,7 @@ func (c *Caches) initList() { return l2 } - c.GTS.List.Init(structr.CacheConfig[*gtsmodel.List]{ + c.DB.List.Init(structr.CacheConfig[*gtsmodel.List]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, }, @@ -879,7 +872,7 @@ func (c *Caches) initListEntry() { return l2 } - c.GTS.ListEntry.Init(structr.CacheConfig[*gtsmodel.ListEntry]{ + c.DB.ListEntry.Init(structr.CacheConfig[*gtsmodel.ListEntry]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "ListID", Multiple: true}, @@ -906,7 +899,7 @@ func (c *Caches) initMarker() { return m2 } - c.GTS.Marker.Init(structr.CacheConfig[*gtsmodel.Marker]{ + c.DB.Marker.Init(structr.CacheConfig[*gtsmodel.Marker]{ Indices: []structr.IndexConfig{ {Fields: "AccountID,Name"}, }, @@ -931,7 +924,7 @@ func (c *Caches) initMedia() { return m2 } - c.GTS.Media.Init(structr.CacheConfig[*gtsmodel.MediaAttachment]{ + c.DB.Media.Init(structr.CacheConfig[*gtsmodel.MediaAttachment]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, }, @@ -965,7 +958,7 @@ func (c *Caches) initMention() { return m2 } - c.GTS.Mention.Init(structr.CacheConfig[*gtsmodel.Mention]{ + c.DB.Mention.Init(structr.CacheConfig[*gtsmodel.Mention]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, }, @@ -984,7 +977,7 @@ func (c *Caches) initMove() { log.Infof(nil, "cache size = %d", cap) - c.GTS.Move.Init(structr.CacheConfig[*gtsmodel.Move]{ + c.DB.Move.Init(structr.CacheConfig[*gtsmodel.Move]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -1025,7 +1018,7 @@ func (c *Caches) initNotification() { return n2 } - c.GTS.Notification.Init(structr.CacheConfig[*gtsmodel.Notification]{ + c.DB.Notification.Init(structr.CacheConfig[*gtsmodel.Notification]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "NotificationType,TargetAccountID,OriginAccountID,StatusID", AllowZero: true}, @@ -1062,7 +1055,7 @@ func (c *Caches) initPoll() { return p2 } - c.GTS.Poll.Init(structr.CacheConfig[*gtsmodel.Poll]{ + c.DB.Poll.Init(structr.CacheConfig[*gtsmodel.Poll]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "StatusID"}, @@ -1096,7 +1089,7 @@ func (c *Caches) initPollVote() { return v2 } - c.GTS.PollVote.Init(structr.CacheConfig[*gtsmodel.PollVote]{ + c.DB.PollVote.Init(structr.CacheConfig[*gtsmodel.PollVote]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "PollID", Multiple: true}, @@ -1117,7 +1110,7 @@ func (c *Caches) initPollVoteIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.PollVoteIDs.Init(0, cap) + c.DB.PollVoteIDs.Init(0, cap) } func (c *Caches) initReport() { @@ -1145,7 +1138,7 @@ func (c *Caches) initReport() { return r2 } - c.GTS.Report.Init(structr.CacheConfig[*gtsmodel.Report]{ + c.DB.Report.Init(structr.CacheConfig[*gtsmodel.Report]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, }, @@ -1186,7 +1179,7 @@ func (c *Caches) initStatus() { return s2 } - c.GTS.Status.Init(structr.CacheConfig[*gtsmodel.Status]{ + c.DB.Status.Init(structr.CacheConfig[*gtsmodel.Status]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -1224,7 +1217,7 @@ func (c *Caches) initStatusBookmark() { return s2 } - c.GTS.StatusBookmark.Init(structr.CacheConfig[*gtsmodel.StatusBookmark]{ + c.DB.StatusBookmark.Init(structr.CacheConfig[*gtsmodel.StatusBookmark]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "AccountID,StatusID"}, @@ -1247,7 +1240,7 @@ func (c *Caches) initStatusBookmarkIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.StatusBookmarkIDs.Init(0, cap) + c.DB.StatusBookmarkIDs.Init(0, cap) } func (c *Caches) initStatusFave() { @@ -1273,7 +1266,7 @@ func (c *Caches) initStatusFave() { return f2 } - c.GTS.StatusFave.Init(structr.CacheConfig[*gtsmodel.StatusFave]{ + c.DB.StatusFave.Init(structr.CacheConfig[*gtsmodel.StatusFave]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -1295,7 +1288,7 @@ func (c *Caches) initStatusFaveIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.StatusFaveIDs.Init(0, cap) + c.DB.StatusFaveIDs.Init(0, cap) } func (c *Caches) initTag() { @@ -1313,7 +1306,7 @@ func (c *Caches) initTag() { return m2 } - c.GTS.Tag.Init(structr.CacheConfig[*gtsmodel.Tag]{ + c.DB.Tag.Init(structr.CacheConfig[*gtsmodel.Tag]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "Name"}, @@ -1338,7 +1331,7 @@ func (c *Caches) initThreadMute() { return t2 } - c.GTS.ThreadMute.Init(structr.CacheConfig[*gtsmodel.ThreadMute]{ + c.DB.ThreadMute.Init(structr.CacheConfig[*gtsmodel.ThreadMute]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "ThreadID", Multiple: true}, @@ -1366,7 +1359,7 @@ func (c *Caches) initToken() { return t2 } - c.GTS.Token.Init(structr.CacheConfig[*gtsmodel.Token]{ + c.DB.Token.Init(structr.CacheConfig[*gtsmodel.Token]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "Code"}, @@ -1395,7 +1388,7 @@ func (c *Caches) initTombstone() { return t2 } - c.GTS.Tombstone.Init(structr.CacheConfig[*gtsmodel.Tombstone]{ + c.DB.Tombstone.Init(structr.CacheConfig[*gtsmodel.Tombstone]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "URI"}, @@ -1427,7 +1420,7 @@ func (c *Caches) initUser() { return u2 } - c.GTS.User.Init(structr.CacheConfig[*gtsmodel.User]{ + c.DB.User.Init(structr.CacheConfig[*gtsmodel.User]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "AccountID"}, @@ -1463,7 +1456,7 @@ func (c *Caches) initUserMute() { return u2 } - c.GTS.UserMute.Init(structr.CacheConfig[*gtsmodel.UserMute]{ + c.DB.UserMute.Init(structr.CacheConfig[*gtsmodel.UserMute]{ Indices: []structr.IndexConfig{ {Fields: "ID"}, {Fields: "AccountID,TargetAccountID"}, @@ -1484,22 +1477,5 @@ func (c *Caches) initUserMuteIDs() { log.Infof(nil, "cache size = %d", cap) - c.GTS.UserMuteIDs.Init(0, cap) -} - -func (c *Caches) initWebfinger() { - // Calculate maximum cache size. - cap := calculateCacheMax( - sizeofURIStr, sizeofURIStr, - config.GetCacheWebfingerMemRatio(), - ) - - log.Infof(nil, "cache size = %d", cap) - - c.GTS.Webfinger = new(ttl.Cache[string, string]) - c.GTS.Webfinger.Init( - 0, - cap, - 24*time.Hour, - ) + c.DB.UserMuteIDs.Init(0, cap) } diff --git a/internal/cache/invalidate.go b/internal/cache/invalidate.go index 987a6eb64..ac326eda3 100644 --- a/internal/cache/invalidate.go +++ b/internal/cache/invalidate.go @@ -28,7 +28,7 @@ import ( func (c *Caches) OnInvalidateAccount(account *gtsmodel.Account) { // Invalidate stats for this account. - c.GTS.AccountStats.Invalidate("AccountID", account.ID) + c.DB.AccountStats.Invalidate("AccountID", account.ID) // Invalidate account ID cached visibility. c.Visibility.Invalidate("ItemID", account.ID) @@ -37,7 +37,7 @@ func (c *Caches) OnInvalidateAccount(account *gtsmodel.Account) { // Invalidate this account's // following / follower lists. // (see FollowIDs() comment for details). - c.GTS.FollowIDs.Invalidate( + c.DB.FollowIDs.Invalidate( ">"+account.ID, "l>"+account.ID, "<"+account.ID, @@ -47,22 +47,22 @@ func (c *Caches) OnInvalidateAccount(account *gtsmodel.Account) { // Invalidate this account's // follow requesting / request lists. // (see FollowRequestIDs() comment for details). - c.GTS.FollowRequestIDs.Invalidate( + c.DB.FollowRequestIDs.Invalidate( ">"+account.ID, "<"+account.ID, ) // Invalidate this account's block lists. - c.GTS.BlockIDs.Invalidate(account.ID) + c.DB.BlockIDs.Invalidate(account.ID) // Invalidate this account's Move(s). - c.GTS.Move.Invalidate("OriginURI", account.URI) - c.GTS.Move.Invalidate("TargetURI", account.URI) + c.DB.Move.Invalidate("OriginURI", account.URI) + c.DB.Move.Invalidate("TargetURI", account.URI) } func (c *Caches) OnInvalidateApplication(app *gtsmodel.Application) { // Invalidate cached client of this application. - c.GTS.Client.Invalidate("ID", app.ClientID) + c.DB.Client.Invalidate("ID", app.ClientID) } func (c *Caches) OnInvalidateBlock(block *gtsmodel.Block) { @@ -75,30 +75,30 @@ func (c *Caches) OnInvalidateBlock(block *gtsmodel.Block) { c.Visibility.Invalidate("RequesterID", block.TargetAccountID) // Invalidate source account's block lists. - c.GTS.BlockIDs.Invalidate(block.AccountID) + c.DB.BlockIDs.Invalidate(block.AccountID) } func (c *Caches) OnInvalidateClient(client *gtsmodel.Client) { // Invalidate any tokens under this client. - c.GTS.Token.Invalidate("ClientID", client.ID) + c.DB.Token.Invalidate("ClientID", client.ID) } func (c *Caches) OnInvalidateConversation(conversation *gtsmodel.Conversation) { // Invalidate owning account's conversation list. - c.GTS.ConversationLastStatusIDs.Invalidate(conversation.AccountID) + c.DB.ConversationLastStatusIDs.Invalidate(conversation.AccountID) } func (c *Caches) OnInvalidateEmojiCategory(category *gtsmodel.EmojiCategory) { // Invalidate any emoji in this category. - c.GTS.Emoji.Invalidate("CategoryID", category.ID) + c.DB.Emoji.Invalidate("CategoryID", category.ID) } func (c *Caches) OnInvalidateFollow(follow *gtsmodel.Follow) { // Invalidate follow request with this same ID. - c.GTS.FollowRequest.Invalidate("ID", follow.ID) + c.DB.FollowRequest.Invalidate("ID", follow.ID) // Invalidate any related list entries. - c.GTS.ListEntry.Invalidate("FollowID", follow.ID) + c.DB.ListEntry.Invalidate("FollowID", follow.ID) // Invalidate follow origin account ID cached visibility. c.Visibility.Invalidate("ItemID", follow.AccountID) @@ -111,7 +111,7 @@ func (c *Caches) OnInvalidateFollow(follow *gtsmodel.Follow) { // Invalidate source account's following // lists, and destination's follwer lists. // (see FollowIDs() comment for details). - c.GTS.FollowIDs.Invalidate( + c.DB.FollowIDs.Invalidate( ">"+follow.AccountID, "l>"+follow.AccountID, "<"+follow.AccountID, @@ -125,12 +125,12 @@ func (c *Caches) OnInvalidateFollow(follow *gtsmodel.Follow) { func (c *Caches) OnInvalidateFollowRequest(followReq *gtsmodel.FollowRequest) { // Invalidate follow with this same ID. - c.GTS.Follow.Invalidate("ID", followReq.ID) + c.DB.Follow.Invalidate("ID", followReq.ID) // Invalidate source account's followreq // lists, and destinations follow req lists. // (see FollowRequestIDs() comment for details). - c.GTS.FollowRequestIDs.Invalidate( + c.DB.FollowRequestIDs.Invalidate( ">"+followReq.AccountID, "<"+followReq.AccountID, ">"+followReq.TargetAccountID, @@ -140,41 +140,41 @@ func (c *Caches) OnInvalidateFollowRequest(followReq *gtsmodel.FollowRequest) { func (c *Caches) OnInvalidateList(list *gtsmodel.List) { // Invalidate all cached entries of this list. - c.GTS.ListEntry.Invalidate("ListID", list.ID) + c.DB.ListEntry.Invalidate("ListID", list.ID) } func (c *Caches) OnInvalidateMedia(media *gtsmodel.MediaAttachment) { if (media.Avatar != nil && *media.Avatar) || (media.Header != nil && *media.Header) { // Invalidate cache of attaching account. - c.GTS.Account.Invalidate("ID", media.AccountID) + c.DB.Account.Invalidate("ID", media.AccountID) } if media.StatusID != "" { // Invalidate cache of attaching status. - c.GTS.Status.Invalidate("ID", media.StatusID) + c.DB.Status.Invalidate("ID", media.StatusID) } } func (c *Caches) OnInvalidatePoll(poll *gtsmodel.Poll) { // Invalidate all cached votes of this poll. - c.GTS.PollVote.Invalidate("PollID", poll.ID) + c.DB.PollVote.Invalidate("PollID", poll.ID) // Invalidate cache of poll vote IDs. - c.GTS.PollVoteIDs.Invalidate(poll.ID) + c.DB.PollVoteIDs.Invalidate(poll.ID) } func (c *Caches) OnInvalidatePollVote(vote *gtsmodel.PollVote) { // Invalidate cached poll (contains no. votes). - c.GTS.Poll.Invalidate("ID", vote.PollID) + c.DB.Poll.Invalidate("ID", vote.PollID) // Invalidate cache of poll vote IDs. - c.GTS.PollVoteIDs.Invalidate(vote.PollID) + c.DB.PollVoteIDs.Invalidate(vote.PollID) } func (c *Caches) OnInvalidateStatus(status *gtsmodel.Status) { // Invalidate stats for this account. - c.GTS.AccountStats.Invalidate("AccountID", status.AccountID) + c.DB.AccountStats.Invalidate("AccountID", status.AccountID) // Invalidate status ID cached visibility. c.Visibility.Invalidate("ItemID", status.ID) @@ -184,33 +184,33 @@ func (c *Caches) OnInvalidateStatus(status *gtsmodel.Status) { // the media IDs in use before the media table is // aware of the status ID they are linked to. // - // c.GTS.Media().Invalidate("StatusID") will not work. - c.GTS.Media.InvalidateIDs("ID", status.AttachmentIDs) + // c.DB.Media().Invalidate("StatusID") will not work. + c.DB.Media.InvalidateIDs("ID", status.AttachmentIDs) if status.BoostOfID != "" { // Invalidate boost ID list of the original status. - c.GTS.BoostOfIDs.Invalidate(status.BoostOfID) + c.DB.BoostOfIDs.Invalidate(status.BoostOfID) } if status.InReplyToID != "" { // Invalidate in reply to ID list of original status. - c.GTS.InReplyToIDs.Invalidate(status.InReplyToID) + c.DB.InReplyToIDs.Invalidate(status.InReplyToID) } if status.PollID != "" { // Invalidate cache of attached poll ID. - c.GTS.Poll.Invalidate("ID", status.PollID) + c.DB.Poll.Invalidate("ID", status.PollID) } } func (c *Caches) OnInvalidateStatusBookmark(bookmark *gtsmodel.StatusBookmark) { // Invalidate status bookmark ID list for this status. - c.GTS.StatusBookmarkIDs.Invalidate(bookmark.StatusID) + c.DB.StatusBookmarkIDs.Invalidate(bookmark.StatusID) } func (c *Caches) OnInvalidateStatusFave(fave *gtsmodel.StatusFave) { // Invalidate status fave ID list for this status. - c.GTS.StatusFaveIDs.Invalidate(fave.StatusID) + c.DB.StatusFaveIDs.Invalidate(fave.StatusID) } func (c *Caches) OnInvalidateUser(user *gtsmodel.User) { @@ -221,5 +221,5 @@ func (c *Caches) OnInvalidateUser(user *gtsmodel.User) { func (c *Caches) OnInvalidateUserMute(mute *gtsmodel.UserMute) { // Invalidate source account's user mute lists. - c.GTS.UserMuteIDs.Invalidate(mute.AccountID) + c.DB.UserMuteIDs.Invalidate(mute.AccountID) } |