[chore] renames the GTS caches to DB caches (#3127)

* renames the `GTS` caches to `DB` caches, as it better references what they are

* change remaining Caches.GTS uses to Caches.DB
This commit is contained in:
kim 2024-07-24 09:41:43 +01:00 committed by GitHub
commit 63fc9b6c3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 376 additions and 378 deletions

122
internal/cache/db.go vendored
View file

@ -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)
}