[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:
parent
325b4a2b4a
commit
63fc9b6c3e
|
@ -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,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ func (a *accountDB) GetAccountByID(ctx context.Context, id string) (*gtsmodel.Ac
|
|||
|
||||
func (a *accountDB) GetAccountsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Account, error) {
|
||||
// Load all input account IDs via cache loader callback.
|
||||
accounts, err := a.state.Caches.GTS.Account.LoadIDs("ID",
|
||||
accounts, err := a.state.Caches.DB.Account.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Account, error) {
|
||||
// Preallocate expected length of uncached accounts.
|
||||
|
@ -587,7 +587,7 @@ func (a *accountDB) GetAccounts(
|
|||
|
||||
func (a *accountDB) getAccount(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Account) error, keyParts ...any) (*gtsmodel.Account, error) {
|
||||
// Fetch account from database cache with loader callback
|
||||
account, err := a.state.Caches.GTS.Account.LoadOne(lookup, func() (*gtsmodel.Account, error) {
|
||||
account, err := a.state.Caches.DB.Account.LoadOne(lookup, func() (*gtsmodel.Account, error) {
|
||||
var account gtsmodel.Account
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -723,7 +723,7 @@ func (a *accountDB) PopulateAccount(ctx context.Context, account *gtsmodel.Accou
|
|||
}
|
||||
|
||||
func (a *accountDB) PutAccount(ctx context.Context, account *gtsmodel.Account) error {
|
||||
return a.state.Caches.GTS.Account.Store(account, func() error {
|
||||
return a.state.Caches.DB.Account.Store(account, func() error {
|
||||
// It is safe to run this database transaction within cache.Store
|
||||
// as the cache does not attempt a mutex lock until AFTER hook.
|
||||
//
|
||||
|
@ -752,7 +752,7 @@ func (a *accountDB) UpdateAccount(ctx context.Context, account *gtsmodel.Account
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return a.state.Caches.GTS.Account.Store(account, func() error {
|
||||
return a.state.Caches.DB.Account.Store(account, func() error {
|
||||
// It is safe to run this database transaction within cache.Store
|
||||
// as the cache does not attempt a mutex lock until AFTER hook.
|
||||
//
|
||||
|
@ -791,7 +791,7 @@ func (a *accountDB) UpdateAccount(ctx context.Context, account *gtsmodel.Account
|
|||
}
|
||||
|
||||
func (a *accountDB) DeleteAccount(ctx context.Context, id string) error {
|
||||
defer a.state.Caches.GTS.Account.Invalidate("ID", id)
|
||||
defer a.state.Caches.DB.Account.Invalidate("ID", id)
|
||||
|
||||
// Load account into cache before attempting a delete,
|
||||
// as we need it cached in order to trigger the invalidate
|
||||
|
@ -1099,7 +1099,7 @@ func (a *accountDB) GetAccountSettings(
|
|||
accountID string,
|
||||
) (*gtsmodel.AccountSettings, error) {
|
||||
// Fetch settings from db cache with loader callback.
|
||||
return a.state.Caches.GTS.AccountSettings.LoadOne(
|
||||
return a.state.Caches.DB.AccountSettings.LoadOne(
|
||||
"AccountID",
|
||||
func() (*gtsmodel.AccountSettings, error) {
|
||||
// Not cached! Perform database query.
|
||||
|
@ -1121,7 +1121,7 @@ func (a *accountDB) PutAccountSettings(
|
|||
ctx context.Context,
|
||||
settings *gtsmodel.AccountSettings,
|
||||
) error {
|
||||
return a.state.Caches.GTS.AccountSettings.Store(settings, func() error {
|
||||
return a.state.Caches.DB.AccountSettings.Store(settings, func() error {
|
||||
if _, err := a.db.
|
||||
NewInsert().
|
||||
Model(settings).
|
||||
|
@ -1138,7 +1138,7 @@ func (a *accountDB) UpdateAccountSettings(
|
|||
settings *gtsmodel.AccountSettings,
|
||||
columns ...string,
|
||||
) error {
|
||||
return a.state.Caches.GTS.AccountSettings.Store(settings, func() error {
|
||||
return a.state.Caches.DB.AccountSettings.Store(settings, func() error {
|
||||
settings.UpdatedAt = time.Now()
|
||||
if len(columns) > 0 {
|
||||
// If we're updating by column,
|
||||
|
@ -1161,7 +1161,7 @@ func (a *accountDB) UpdateAccountSettings(
|
|||
|
||||
func (a *accountDB) PopulateAccountStats(ctx context.Context, account *gtsmodel.Account) error {
|
||||
// Fetch stats from db cache with loader callback.
|
||||
stats, err := a.state.Caches.GTS.AccountStats.LoadOne(
|
||||
stats, err := a.state.Caches.DB.AccountStats.LoadOne(
|
||||
"AccountID",
|
||||
func() (*gtsmodel.AccountStats, error) {
|
||||
// Not cached! Perform database query.
|
||||
|
@ -1230,7 +1230,7 @@ func (a *accountDB) StubAccountStats(ctx context.Context, account *gtsmodel.Acco
|
|||
|
||||
// Upsert this stats in case a race
|
||||
// meant someone else inserted it first.
|
||||
if err := a.state.Caches.GTS.AccountStats.Store(stats, func() error {
|
||||
if err := a.state.Caches.DB.AccountStats.Store(stats, func() error {
|
||||
if _, err := NewUpsert(a.db).
|
||||
Model(stats).
|
||||
Constraint("account_id").
|
||||
|
@ -1325,7 +1325,7 @@ func (a *accountDB) RegenerateAccountStats(ctx context.Context, account *gtsmode
|
|||
|
||||
// Upsert this stats in case a race
|
||||
// meant someone else inserted it first.
|
||||
if err := a.state.Caches.GTS.AccountStats.Store(stats, func() error {
|
||||
if err := a.state.Caches.DB.AccountStats.Store(stats, func() error {
|
||||
if _, err := NewUpsert(a.db).
|
||||
Model(stats).
|
||||
Constraint("account_id").
|
||||
|
@ -1342,7 +1342,7 @@ func (a *accountDB) RegenerateAccountStats(ctx context.Context, account *gtsmode
|
|||
}
|
||||
|
||||
func (a *accountDB) UpdateAccountStats(ctx context.Context, stats *gtsmodel.AccountStats, columns ...string) error {
|
||||
return a.state.Caches.GTS.AccountStats.Store(stats, func() error {
|
||||
return a.state.Caches.DB.AccountStats.Store(stats, func() error {
|
||||
if _, err := a.db.
|
||||
NewUpdate().
|
||||
Model(stats).
|
||||
|
@ -1357,7 +1357,7 @@ func (a *accountDB) UpdateAccountStats(ctx context.Context, stats *gtsmodel.Acco
|
|||
}
|
||||
|
||||
func (a *accountDB) DeleteAccountStats(ctx context.Context, accountID string) error {
|
||||
defer a.state.Caches.GTS.AccountStats.Invalidate("AccountID", accountID)
|
||||
defer a.state.Caches.DB.AccountStats.Invalidate("AccountID", accountID)
|
||||
|
||||
if _, err := a.db.
|
||||
NewDelete().
|
||||
|
|
|
@ -54,7 +54,7 @@ func (a *applicationDB) GetApplicationByClientID(ctx context.Context, clientID s
|
|||
}
|
||||
|
||||
func (a *applicationDB) getApplication(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Application) error, keyParts ...any) (*gtsmodel.Application, error) {
|
||||
return a.state.Caches.GTS.Application.LoadOne(lookup, func() (*gtsmodel.Application, error) {
|
||||
return a.state.Caches.DB.Application.LoadOne(lookup, func() (*gtsmodel.Application, error) {
|
||||
var app gtsmodel.Application
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -67,7 +67,7 @@ func (a *applicationDB) getApplication(ctx context.Context, lookup string, dbQue
|
|||
}
|
||||
|
||||
func (a *applicationDB) PutApplication(ctx context.Context, app *gtsmodel.Application) error {
|
||||
return a.state.Caches.GTS.Application.Store(app, func() error {
|
||||
return a.state.Caches.DB.Application.Store(app, func() error {
|
||||
_, err := a.db.NewInsert().Model(app).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -92,13 +92,13 @@ func (a *applicationDB) DeleteApplicationByClientID(ctx context.Context, clientI
|
|||
//
|
||||
|
||||
// Clear application from the cache.
|
||||
a.state.Caches.GTS.Application.Invalidate("ClientID", clientID)
|
||||
a.state.Caches.DB.Application.Invalidate("ClientID", clientID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *applicationDB) GetClientByID(ctx context.Context, id string) (*gtsmodel.Client, error) {
|
||||
return a.state.Caches.GTS.Client.LoadOne("ID", func() (*gtsmodel.Client, error) {
|
||||
return a.state.Caches.DB.Client.LoadOne("ID", func() (*gtsmodel.Client, error) {
|
||||
var client gtsmodel.Client
|
||||
|
||||
if err := a.db.NewSelect().
|
||||
|
@ -113,7 +113,7 @@ func (a *applicationDB) GetClientByID(ctx context.Context, id string) (*gtsmodel
|
|||
}
|
||||
|
||||
func (a *applicationDB) PutClient(ctx context.Context, client *gtsmodel.Client) error {
|
||||
return a.state.Caches.GTS.Client.Store(client, func() error {
|
||||
return a.state.Caches.DB.Client.Store(client, func() error {
|
||||
_, err := a.db.NewInsert().Model(client).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -128,7 +128,7 @@ func (a *applicationDB) DeleteClientByID(ctx context.Context, id string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
a.state.Caches.GTS.Client.Invalidate("ID", id)
|
||||
a.state.Caches.DB.Client.Invalidate("ID", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ func (a *applicationDB) GetAllTokens(ctx context.Context) ([]*gtsmodel.Token, er
|
|||
}
|
||||
|
||||
// Load all input token IDs via cache loader callback.
|
||||
tokens, err := a.state.Caches.GTS.Token.LoadIDs("ID",
|
||||
tokens, err := a.state.Caches.DB.Token.LoadIDs("ID",
|
||||
tokenIDs,
|
||||
func(uncached []string) ([]*gtsmodel.Token, error) {
|
||||
// Preallocate expected length of uncached tokens.
|
||||
|
@ -205,7 +205,7 @@ func (a *applicationDB) GetTokenByRefresh(ctx context.Context, refresh string) (
|
|||
}
|
||||
|
||||
func (a *applicationDB) getTokenBy(lookup string, dbQuery func(*gtsmodel.Token) error, keyParts ...any) (*gtsmodel.Token, error) {
|
||||
return a.state.Caches.GTS.Token.LoadOne(lookup, func() (*gtsmodel.Token, error) {
|
||||
return a.state.Caches.DB.Token.LoadOne(lookup, func() (*gtsmodel.Token, error) {
|
||||
var token gtsmodel.Token
|
||||
|
||||
if err := dbQuery(&token); err != nil {
|
||||
|
@ -217,7 +217,7 @@ func (a *applicationDB) getTokenBy(lookup string, dbQuery func(*gtsmodel.Token)
|
|||
}
|
||||
|
||||
func (a *applicationDB) PutToken(ctx context.Context, token *gtsmodel.Token) error {
|
||||
return a.state.Caches.GTS.Token.Store(token, func() error {
|
||||
return a.state.Caches.DB.Token.Store(token, func() error {
|
||||
_, err := a.db.NewInsert().Model(token).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -232,7 +232,7 @@ func (a *applicationDB) DeleteTokenByID(ctx context.Context, id string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
a.state.Caches.GTS.Token.Invalidate("ID", id)
|
||||
a.state.Caches.DB.Token.Invalidate("ID", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,7 @@ func (a *applicationDB) DeleteTokenByCode(ctx context.Context, code string) erro
|
|||
return err
|
||||
}
|
||||
|
||||
a.state.Caches.GTS.Token.Invalidate("Code", code)
|
||||
a.state.Caches.DB.Token.Invalidate("Code", code)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ func (a *applicationDB) DeleteTokenByAccess(ctx context.Context, access string)
|
|||
return err
|
||||
}
|
||||
|
||||
a.state.Caches.GTS.Token.Invalidate("Access", access)
|
||||
a.state.Caches.DB.Token.Invalidate("Access", access)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -271,6 +271,6 @@ func (a *applicationDB) DeleteTokenByRefresh(ctx context.Context, refresh string
|
|||
return err
|
||||
}
|
||||
|
||||
a.state.Caches.GTS.Token.Invalidate("Refresh", refresh)
|
||||
a.state.Caches.DB.Token.Invalidate("Refresh", refresh)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ func (c *conversationDB) getConversation(
|
|||
keyParts ...any,
|
||||
) (*gtsmodel.Conversation, error) {
|
||||
// Fetch conversation from cache with loader callback
|
||||
conversation, err := c.state.Caches.GTS.Conversation.LoadOne(lookup, func() (*gtsmodel.Conversation, error) {
|
||||
conversation, err := c.state.Caches.DB.Conversation.LoadOne(lookup, func() (*gtsmodel.Conversation, error) {
|
||||
var conversation gtsmodel.Conversation
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -157,7 +157,7 @@ func (c *conversationDB) GetConversationsByOwnerAccountID(ctx context.Context, a
|
|||
}
|
||||
|
||||
func (c *conversationDB) getAccountConversationLastStatusIDs(ctx context.Context, accountID string, page *paging.Page) ([]string, error) {
|
||||
return loadPagedIDs(&c.state.Caches.GTS.ConversationLastStatusIDs, accountID, page, func() ([]string, error) {
|
||||
return loadPagedIDs(&c.state.Caches.DB.ConversationLastStatusIDs, accountID, page, func() ([]string, error) {
|
||||
var conversationLastStatusIDs []string
|
||||
|
||||
// Conversation last status IDs not in cache. Perform DB query.
|
||||
|
@ -182,7 +182,7 @@ func (c *conversationDB) getConversationsByLastStatusIDs(
|
|||
conversationLastStatusIDs []string,
|
||||
) ([]*gtsmodel.Conversation, error) {
|
||||
// Load all conversation IDs via cache loader callbacks.
|
||||
conversations, err := c.state.Caches.GTS.Conversation.LoadIDs2Part(
|
||||
conversations, err := c.state.Caches.DB.Conversation.LoadIDs2Part(
|
||||
"AccountID,LastStatusID",
|
||||
accountID,
|
||||
conversationLastStatusIDs,
|
||||
|
@ -233,7 +233,7 @@ func (c *conversationDB) UpsertConversation(ctx context.Context, conversation *g
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return c.state.Caches.GTS.Conversation.Store(conversation, func() error {
|
||||
return c.state.Caches.DB.Conversation.Store(conversation, func() error {
|
||||
_, err := NewUpsert(c.db).
|
||||
Model(conversation).
|
||||
Constraint("id").
|
||||
|
@ -272,7 +272,7 @@ func (c *conversationDB) DeleteConversationByID(ctx context.Context, id string)
|
|||
}
|
||||
|
||||
// Drop this now-cached conversation on return after delete.
|
||||
defer c.state.Caches.GTS.Conversation.Invalidate("ID", id)
|
||||
defer c.state.Caches.DB.Conversation.Invalidate("ID", id)
|
||||
|
||||
// Finally delete conversation from DB.
|
||||
_, err = c.db.NewDelete().
|
||||
|
@ -288,10 +288,10 @@ func (c *conversationDB) DeleteConversationsByOwnerAccountID(ctx context.Context
|
|||
// Conversation invalidate hooks only invalidate the conversation ID cache,
|
||||
// so we don't need to load all conversations into the cache to run invalidation hooks,
|
||||
// as with some other object types (blocks, for example).
|
||||
c.state.Caches.GTS.Conversation.Invalidate("AccountID", accountID)
|
||||
c.state.Caches.DB.Conversation.Invalidate("AccountID", accountID)
|
||||
// In case there were no cached conversations,
|
||||
// explicitly invalidate the user's conversation last status ID cache.
|
||||
c.state.Caches.GTS.ConversationLastStatusIDs.Invalidate(accountID)
|
||||
c.state.Caches.DB.ConversationLastStatusIDs.Invalidate(accountID)
|
||||
}()
|
||||
|
||||
return c.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
|
@ -488,7 +488,7 @@ func (c *conversationDB) DeleteStatusFromConversations(ctx context.Context, stat
|
|||
}
|
||||
|
||||
updatedConversationIDs = append(updatedConversationIDs, deletedConversationIDs...)
|
||||
c.state.Caches.GTS.Conversation.InvalidateIDs("ID", updatedConversationIDs)
|
||||
c.state.Caches.DB.Conversation.InvalidateIDs("ID", updatedConversationIDs)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func (d *domainDB) CreateDomainAllow(ctx context.Context, allow *gtsmodel.Domain
|
|||
}
|
||||
|
||||
// Clear the domain allow cache (for later reload)
|
||||
d.state.Caches.GTS.DomainAllow.Clear()
|
||||
d.state.Caches.DB.DomainAllow.Clear()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func (d *domainDB) DeleteDomainAllow(ctx context.Context, domain string) error {
|
|||
}
|
||||
|
||||
// Clear the domain allow cache (for later reload)
|
||||
d.state.Caches.GTS.DomainAllow.Clear()
|
||||
d.state.Caches.DB.DomainAllow.Clear()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ func (d *domainDB) CreateDomainBlock(ctx context.Context, block *gtsmodel.Domain
|
|||
}
|
||||
|
||||
// Clear the domain block cache (for later reload)
|
||||
d.state.Caches.GTS.DomainBlock.Clear()
|
||||
d.state.Caches.DB.DomainBlock.Clear()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ func (d *domainDB) DeleteDomainBlock(ctx context.Context, domain string) error {
|
|||
}
|
||||
|
||||
// Clear the domain block cache (for later reload)
|
||||
d.state.Caches.GTS.DomainBlock.Clear()
|
||||
d.state.Caches.DB.DomainBlock.Clear()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ func (d *domainDB) IsDomainBlocked(ctx context.Context, domain string) (bool, er
|
|||
}
|
||||
|
||||
// Check the cache for an explicit domain allow (hydrating the cache with callback if necessary).
|
||||
explicitAllow, err := d.state.Caches.GTS.DomainAllow.Matches(domain, func() ([]string, error) {
|
||||
explicitAllow, err := d.state.Caches.DB.DomainAllow.Matches(domain, func() ([]string, error) {
|
||||
var domains []string
|
||||
|
||||
// Scan list of all explicitly allowed domains from DB
|
||||
|
@ -259,7 +259,7 @@ func (d *domainDB) IsDomainBlocked(ctx context.Context, domain string) (bool, er
|
|||
}
|
||||
|
||||
// Check the cache for a domain block (hydrating the cache with callback if necessary)
|
||||
explicitBlock, err := d.state.Caches.GTS.DomainBlock.Matches(domain, func() ([]string, error) {
|
||||
explicitBlock, err := d.state.Caches.DB.DomainBlock.Matches(domain, func() ([]string, error) {
|
||||
var domains []string
|
||||
|
||||
// Scan list of all blocked domains from DB
|
||||
|
|
|
@ -43,7 +43,7 @@ type emojiDB struct {
|
|||
}
|
||||
|
||||
func (e *emojiDB) PutEmoji(ctx context.Context, emoji *gtsmodel.Emoji) error {
|
||||
return e.state.Caches.GTS.Emoji.Store(emoji, func() error {
|
||||
return e.state.Caches.DB.Emoji.Store(emoji, func() error {
|
||||
_, err := e.db.NewInsert().Model(emoji).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -57,7 +57,7 @@ func (e *emojiDB) UpdateEmoji(ctx context.Context, emoji *gtsmodel.Emoji, column
|
|||
}
|
||||
|
||||
// Update the emoji model in the database.
|
||||
return e.state.Caches.GTS.Emoji.Store(emoji, func() error {
|
||||
return e.state.Caches.DB.Emoji.Store(emoji, func() error {
|
||||
_, err := e.db.
|
||||
NewUpdate().
|
||||
Model(emoji).
|
||||
|
@ -76,11 +76,11 @@ func (e *emojiDB) DeleteEmojiByID(ctx context.Context, id string) error {
|
|||
|
||||
defer func() {
|
||||
// Invalidate cached emoji.
|
||||
e.state.Caches.GTS.Emoji.Invalidate("ID", id)
|
||||
e.state.Caches.DB.Emoji.Invalidate("ID", id)
|
||||
|
||||
// Invalidate cached account and status IDs.
|
||||
e.state.Caches.GTS.Account.InvalidateIDs("ID", accountIDs)
|
||||
e.state.Caches.GTS.Status.InvalidateIDs("ID", statusIDs)
|
||||
e.state.Caches.DB.Account.InvalidateIDs("ID", accountIDs)
|
||||
e.state.Caches.DB.Status.InvalidateIDs("ID", statusIDs)
|
||||
}()
|
||||
|
||||
// Load emoji into cache before attempting a delete,
|
||||
|
@ -477,7 +477,7 @@ func (e *emojiDB) GetEmojiByStaticURL(ctx context.Context, imageStaticURL string
|
|||
}
|
||||
|
||||
func (e *emojiDB) PutEmojiCategory(ctx context.Context, emojiCategory *gtsmodel.EmojiCategory) error {
|
||||
return e.state.Caches.GTS.EmojiCategory.Store(emojiCategory, func() error {
|
||||
return e.state.Caches.DB.EmojiCategory.Store(emojiCategory, func() error {
|
||||
_, err := e.db.NewInsert().Model(emojiCategory).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -529,7 +529,7 @@ func (e *emojiDB) GetEmojiCategoryByName(ctx context.Context, name string) (*gts
|
|||
|
||||
func (e *emojiDB) getEmoji(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Emoji) error, keyParts ...any) (*gtsmodel.Emoji, error) {
|
||||
// Fetch emoji from database cache with loader callback
|
||||
emoji, err := e.state.Caches.GTS.Emoji.LoadOne(lookup, func() (*gtsmodel.Emoji, error) {
|
||||
emoji, err := e.state.Caches.DB.Emoji.LoadOne(lookup, func() (*gtsmodel.Emoji, error) {
|
||||
var emoji gtsmodel.Emoji
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -583,7 +583,7 @@ func (e *emojiDB) GetEmojisByIDs(ctx context.Context, ids []string) ([]*gtsmodel
|
|||
}
|
||||
|
||||
// Load all emoji IDs via cache loader callbacks.
|
||||
emojis, err := e.state.Caches.GTS.Emoji.LoadIDs("ID",
|
||||
emojis, err := e.state.Caches.DB.Emoji.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Emoji, error) {
|
||||
// Preallocate expected length of uncached emojis.
|
||||
|
@ -629,7 +629,7 @@ func (e *emojiDB) GetEmojisByIDs(ctx context.Context, ids []string) ([]*gtsmodel
|
|||
}
|
||||
|
||||
func (e *emojiDB) getEmojiCategory(ctx context.Context, lookup string, dbQuery func(*gtsmodel.EmojiCategory) error, keyParts ...any) (*gtsmodel.EmojiCategory, error) {
|
||||
return e.state.Caches.GTS.EmojiCategory.LoadOne(lookup, func() (*gtsmodel.EmojiCategory, error) {
|
||||
return e.state.Caches.DB.EmojiCategory.LoadOne(lookup, func() (*gtsmodel.EmojiCategory, error) {
|
||||
var category gtsmodel.EmojiCategory
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -647,7 +647,7 @@ func (e *emojiDB) GetEmojiCategoriesByIDs(ctx context.Context, ids []string) ([]
|
|||
}
|
||||
|
||||
// Load all category IDs via cache loader callbacks.
|
||||
categories, err := e.state.Caches.GTS.EmojiCategory.LoadIDs("ID",
|
||||
categories, err := e.state.Caches.DB.EmojiCategory.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.EmojiCategory, error) {
|
||||
// Preallocate expected length of uncached categories.
|
||||
|
|
|
@ -37,7 +37,7 @@ type filterDB struct {
|
|||
}
|
||||
|
||||
func (f *filterDB) GetFilterByID(ctx context.Context, id string) (*gtsmodel.Filter, error) {
|
||||
filter, err := f.state.Caches.GTS.Filter.LoadOne(
|
||||
filter, err := f.state.Caches.DB.Filter.LoadOne(
|
||||
"ID",
|
||||
func() (*gtsmodel.Filter, error) {
|
||||
var filter gtsmodel.Filter
|
||||
|
@ -80,7 +80,7 @@ func (f *filterDB) GetFiltersForAccountID(ctx context.Context, accountID string)
|
|||
}
|
||||
|
||||
// Get each filter by ID from the cache or DB.
|
||||
filters, err := f.state.Caches.GTS.Filter.LoadIDs("ID",
|
||||
filters, err := f.state.Caches.DB.Filter.LoadIDs("ID",
|
||||
filterIDs,
|
||||
func(uncachedFilterIDs []string) ([]*gtsmodel.Filter, error) {
|
||||
uncachedFilters := make([]*gtsmodel.Filter, 0, len(uncachedFilterIDs))
|
||||
|
@ -194,9 +194,9 @@ func (f *filterDB) PutFilter(ctx context.Context, filter *gtsmodel.Filter) error
|
|||
}
|
||||
|
||||
// Update cache.
|
||||
f.state.Caches.GTS.Filter.Put(filter)
|
||||
f.state.Caches.GTS.FilterKeyword.Put(filter.Keywords...)
|
||||
f.state.Caches.GTS.FilterStatus.Put(filter.Statuses...)
|
||||
f.state.Caches.DB.Filter.Put(filter)
|
||||
f.state.Caches.DB.FilterKeyword.Put(filter.Keywords...)
|
||||
f.state.Caches.DB.FilterStatus.Put(filter.Statuses...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -296,15 +296,15 @@ func (f *filterDB) UpdateFilter(
|
|||
}
|
||||
|
||||
// Update cache.
|
||||
f.state.Caches.GTS.Filter.Put(filter)
|
||||
f.state.Caches.GTS.FilterKeyword.Put(filter.Keywords...)
|
||||
f.state.Caches.GTS.FilterStatus.Put(filter.Statuses...)
|
||||
f.state.Caches.DB.Filter.Put(filter)
|
||||
f.state.Caches.DB.FilterKeyword.Put(filter.Keywords...)
|
||||
f.state.Caches.DB.FilterStatus.Put(filter.Statuses...)
|
||||
// TODO: (Vyr) replace with cache multi-invalidate call
|
||||
for _, id := range deleteFilterKeywordIDs {
|
||||
f.state.Caches.GTS.FilterKeyword.Invalidate("ID", id)
|
||||
f.state.Caches.DB.FilterKeyword.Invalidate("ID", id)
|
||||
}
|
||||
for _, id := range deleteFilterStatusIDs {
|
||||
f.state.Caches.GTS.FilterStatus.Invalidate("ID", id)
|
||||
f.state.Caches.DB.FilterStatus.Invalidate("ID", id)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -342,11 +342,11 @@ func (f *filterDB) DeleteFilterByID(ctx context.Context, id string) error {
|
|||
}
|
||||
|
||||
// Invalidate this filter.
|
||||
f.state.Caches.GTS.Filter.Invalidate("ID", id)
|
||||
f.state.Caches.DB.Filter.Invalidate("ID", id)
|
||||
|
||||
// Invalidate all keywords and statuses for this filter.
|
||||
f.state.Caches.GTS.FilterKeyword.Invalidate("FilterID", id)
|
||||
f.state.Caches.GTS.FilterStatus.Invalidate("FilterID", id)
|
||||
f.state.Caches.DB.FilterKeyword.Invalidate("FilterID", id)
|
||||
f.state.Caches.DB.FilterStatus.Invalidate("FilterID", id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import (
|
|||
)
|
||||
|
||||
func (f *filterDB) GetFilterKeywordByID(ctx context.Context, id string) (*gtsmodel.FilterKeyword, error) {
|
||||
filterKeyword, err := f.state.Caches.GTS.FilterKeyword.LoadOne(
|
||||
filterKeyword, err := f.state.Caches.DB.FilterKeyword.LoadOne(
|
||||
"ID",
|
||||
func() (*gtsmodel.FilterKeyword, error) {
|
||||
var filterKeyword gtsmodel.FilterKeyword
|
||||
|
@ -110,7 +110,7 @@ func (f *filterDB) getFilterKeywords(ctx context.Context, idColumn string, id st
|
|||
}
|
||||
|
||||
// Get each filter keyword by ID from the cache or DB.
|
||||
filterKeywords, err := f.state.Caches.GTS.FilterKeyword.LoadIDs("ID",
|
||||
filterKeywords, err := f.state.Caches.DB.FilterKeyword.LoadIDs("ID",
|
||||
filterKeywordIDs,
|
||||
func(uncachedFilterKeywordIDs []string) ([]*gtsmodel.FilterKeyword, error) {
|
||||
uncachedFilterKeywords := make([]*gtsmodel.FilterKeyword, 0, len(uncachedFilterKeywordIDs))
|
||||
|
@ -170,7 +170,7 @@ func (f *filterDB) PutFilterKeyword(ctx context.Context, filterKeyword *gtsmodel
|
|||
return gtserror.Newf("error compiling filter keyword regex: %w", err)
|
||||
}
|
||||
}
|
||||
return f.state.Caches.GTS.FilterKeyword.Store(filterKeyword, func() error {
|
||||
return f.state.Caches.DB.FilterKeyword.Store(filterKeyword, func() error {
|
||||
_, err := f.db.
|
||||
NewInsert().
|
||||
Model(filterKeyword).
|
||||
|
@ -192,7 +192,7 @@ func (f *filterDB) UpdateFilterKeyword(ctx context.Context, filterKeyword *gtsmo
|
|||
return gtserror.Newf("error compiling filter keyword regex: %w", err)
|
||||
}
|
||||
}
|
||||
return f.state.Caches.GTS.FilterKeyword.Store(filterKeyword, func() error {
|
||||
return f.state.Caches.DB.FilterKeyword.Store(filterKeyword, func() error {
|
||||
_, err := f.db.
|
||||
NewUpdate().
|
||||
Model(filterKeyword).
|
||||
|
@ -212,7 +212,7 @@ func (f *filterDB) DeleteFilterKeywordByID(ctx context.Context, id string) error
|
|||
return err
|
||||
}
|
||||
|
||||
f.state.Caches.GTS.FilterKeyword.Invalidate("ID", id)
|
||||
f.state.Caches.DB.FilterKeyword.Invalidate("ID", id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import (
|
|||
)
|
||||
|
||||
func (f *filterDB) GetFilterStatusByID(ctx context.Context, id string) (*gtsmodel.FilterStatus, error) {
|
||||
filterStatus, err := f.state.Caches.GTS.FilterStatus.LoadOne(
|
||||
filterStatus, err := f.state.Caches.DB.FilterStatus.LoadOne(
|
||||
"ID",
|
||||
func() (*gtsmodel.FilterStatus, error) {
|
||||
var filterStatus gtsmodel.FilterStatus
|
||||
|
@ -97,7 +97,7 @@ func (f *filterDB) getFilterStatuses(ctx context.Context, idColumn string, id st
|
|||
}
|
||||
|
||||
// Get each filter status by ID from the cache or DB.
|
||||
filterStatuses, err := f.state.Caches.GTS.FilterStatus.LoadIDs("ID",
|
||||
filterStatuses, err := f.state.Caches.DB.FilterStatus.LoadIDs("ID",
|
||||
filterStatusIDs,
|
||||
func(uncachedFilterStatusIDs []string) ([]*gtsmodel.FilterStatus, error) {
|
||||
uncachedFilterStatuses := make([]*gtsmodel.FilterStatus, 0, len(uncachedFilterStatusIDs))
|
||||
|
@ -142,7 +142,7 @@ func (f *filterDB) getFilterStatuses(ctx context.Context, idColumn string, id st
|
|||
}
|
||||
|
||||
func (f *filterDB) PutFilterStatus(ctx context.Context, filterStatus *gtsmodel.FilterStatus) error {
|
||||
return f.state.Caches.GTS.FilterStatus.Store(filterStatus, func() error {
|
||||
return f.state.Caches.DB.FilterStatus.Store(filterStatus, func() error {
|
||||
_, err := f.db.
|
||||
NewInsert().
|
||||
Model(filterStatus).
|
||||
|
@ -157,7 +157,7 @@ func (f *filterDB) UpdateFilterStatus(ctx context.Context, filterStatus *gtsmode
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return f.state.Caches.GTS.FilterStatus.Store(filterStatus, func() error {
|
||||
return f.state.Caches.DB.FilterStatus.Store(filterStatus, func() error {
|
||||
_, err := f.db.
|
||||
NewUpdate().
|
||||
Model(filterStatus).
|
||||
|
@ -177,7 +177,7 @@ func (f *filterDB) DeleteFilterStatusByID(ctx context.Context, id string) error
|
|||
return err
|
||||
}
|
||||
|
||||
f.state.Caches.GTS.FilterStatus.Invalidate("ID", id)
|
||||
f.state.Caches.DB.FilterStatus.Invalidate("ID", id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ func (i *instanceDB) GetInstanceByID(ctx context.Context, id string) (*gtsmodel.
|
|||
|
||||
func (i *instanceDB) getInstance(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Instance) error, keyParts ...any) (*gtsmodel.Instance, error) {
|
||||
// Fetch instance from database cache with loader callback
|
||||
instance, err := i.state.Caches.GTS.Instance.LoadOne(lookup, func() (*gtsmodel.Instance, error) {
|
||||
instance, err := i.state.Caches.DB.Instance.LoadOne(lookup, func() (*gtsmodel.Instance, error) {
|
||||
var instance gtsmodel.Instance
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -219,7 +219,7 @@ func (i *instanceDB) PutInstance(ctx context.Context, instance *gtsmodel.Instanc
|
|||
return gtserror.Newf("error punifying domain %s: %w", instance.Domain, err)
|
||||
}
|
||||
|
||||
return i.state.Caches.GTS.Instance.Store(instance, func() error {
|
||||
return i.state.Caches.DB.Instance.Store(instance, func() error {
|
||||
_, err := i.db.NewInsert().Model(instance).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -239,7 +239,7 @@ func (i *instanceDB) UpdateInstance(ctx context.Context, instance *gtsmodel.Inst
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return i.state.Caches.GTS.Instance.Store(instance, func() error {
|
||||
return i.state.Caches.DB.Instance.Store(instance, func() error {
|
||||
_, err := i.db.
|
||||
NewUpdate().
|
||||
Model(instance).
|
||||
|
|
|
@ -73,7 +73,7 @@ func (r *interactionDB) getInteractionApproval(
|
|||
keyParts ...any,
|
||||
) (*gtsmodel.InteractionApproval, error) {
|
||||
// Fetch approval from database cache with loader callback
|
||||
approval, err := r.state.Caches.GTS.InteractionApproval.LoadOne(lookup, func() (*gtsmodel.InteractionApproval, error) {
|
||||
approval, err := r.state.Caches.DB.InteractionApproval.LoadOne(lookup, func() (*gtsmodel.InteractionApproval, error) {
|
||||
var approval gtsmodel.InteractionApproval
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -132,14 +132,14 @@ func (r *interactionDB) PopulateInteractionApproval(ctx context.Context, approva
|
|||
}
|
||||
|
||||
func (r *interactionDB) PutInteractionApproval(ctx context.Context, approval *gtsmodel.InteractionApproval) error {
|
||||
return r.state.Caches.GTS.InteractionApproval.Store(approval, func() error {
|
||||
return r.state.Caches.DB.InteractionApproval.Store(approval, func() error {
|
||||
_, err := r.db.NewInsert().Model(approval).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (r *interactionDB) DeleteInteractionApprovalByID(ctx context.Context, id string) error {
|
||||
defer r.state.Caches.GTS.InteractionApproval.Invalidate("ID", id)
|
||||
defer r.state.Caches.DB.InteractionApproval.Invalidate("ID", id)
|
||||
|
||||
_, err := r.db.NewDelete().
|
||||
TableExpr("? AS ?", bun.Ident("interaction_approvals"), bun.Ident("interaction_approval")).
|
||||
|
|
|
@ -58,7 +58,7 @@ func (l *listDB) GetListByID(ctx context.Context, id string) (*gtsmodel.List, er
|
|||
}
|
||||
|
||||
func (l *listDB) getList(ctx context.Context, lookup string, dbQuery func(*gtsmodel.List) error, keyParts ...any) (*gtsmodel.List, error) {
|
||||
list, err := l.state.Caches.GTS.List.LoadOne(lookup, func() (*gtsmodel.List, error) {
|
||||
list, err := l.state.Caches.DB.List.LoadOne(lookup, func() (*gtsmodel.List, error) {
|
||||
var list gtsmodel.List
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -139,7 +139,7 @@ func (l *listDB) PopulateList(ctx context.Context, list *gtsmodel.List) error {
|
|||
}
|
||||
|
||||
func (l *listDB) PutList(ctx context.Context, list *gtsmodel.List) error {
|
||||
return l.state.Caches.GTS.List.Store(list, func() error {
|
||||
return l.state.Caches.DB.List.Store(list, func() error {
|
||||
_, err := l.db.NewInsert().Model(list).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -154,7 +154,7 @@ func (l *listDB) UpdateList(ctx context.Context, list *gtsmodel.List, columns ..
|
|||
|
||||
defer func() {
|
||||
// Invalidate all entries for this list ID.
|
||||
l.state.Caches.GTS.ListEntry.Invalidate("ListID", list.ID)
|
||||
l.state.Caches.DB.ListEntry.Invalidate("ListID", list.ID)
|
||||
|
||||
// Invalidate this entire list's timeline.
|
||||
if err := l.state.Timelines.List.RemoveTimeline(ctx, list.ID); err != nil {
|
||||
|
@ -162,7 +162,7 @@ func (l *listDB) UpdateList(ctx context.Context, list *gtsmodel.List, columns ..
|
|||
}
|
||||
}()
|
||||
|
||||
return l.state.Caches.GTS.List.Store(list, func() error {
|
||||
return l.state.Caches.DB.List.Store(list, func() error {
|
||||
_, err := l.db.NewUpdate().
|
||||
Model(list).
|
||||
Where("? = ?", bun.Ident("list.id"), list.ID).
|
||||
|
@ -190,7 +190,7 @@ func (l *listDB) DeleteListByID(ctx context.Context, id string) error {
|
|||
|
||||
defer func() {
|
||||
// Invalidate this list from cache.
|
||||
l.state.Caches.GTS.List.Invalidate("ID", id)
|
||||
l.state.Caches.DB.List.Invalidate("ID", id)
|
||||
|
||||
// Invalidate this entire list's timeline.
|
||||
if err := l.state.Timelines.List.RemoveTimeline(ctx, id); err != nil {
|
||||
|
@ -235,7 +235,7 @@ func (l *listDB) GetListEntryByID(ctx context.Context, id string) (*gtsmodel.Lis
|
|||
}
|
||||
|
||||
func (l *listDB) getListEntry(ctx context.Context, lookup string, dbQuery func(*gtsmodel.ListEntry) error, keyParts ...any) (*gtsmodel.ListEntry, error) {
|
||||
listEntry, err := l.state.Caches.GTS.ListEntry.LoadOne(lookup, func() (*gtsmodel.ListEntry, error) {
|
||||
listEntry, err := l.state.Caches.DB.ListEntry.LoadOne(lookup, func() (*gtsmodel.ListEntry, error) {
|
||||
var listEntry gtsmodel.ListEntry
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -342,7 +342,7 @@ func (l *listDB) GetListEntries(ctx context.Context,
|
|||
|
||||
func (l *listDB) GetListsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.List, error) {
|
||||
// Load all list IDs via cache loader callbacks.
|
||||
lists, err := l.state.Caches.GTS.List.LoadIDs("ID",
|
||||
lists, err := l.state.Caches.DB.List.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.List, error) {
|
||||
// Preallocate expected length of uncached lists.
|
||||
|
@ -389,7 +389,7 @@ func (l *listDB) GetListsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.L
|
|||
|
||||
func (l *listDB) GetListEntriesByIDs(ctx context.Context, ids []string) ([]*gtsmodel.ListEntry, error) {
|
||||
// Load all entry IDs via cache loader callbacks.
|
||||
entries, err := l.state.Caches.GTS.ListEntry.LoadIDs("ID",
|
||||
entries, err := l.state.Caches.DB.ListEntry.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.ListEntry, error) {
|
||||
// Preallocate expected length of uncached entries.
|
||||
|
@ -492,7 +492,7 @@ func (l *listDB) PutListEntries(ctx context.Context, entries []*gtsmodel.ListEnt
|
|||
return l.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
for _, entry := range entries {
|
||||
entry := entry // rescope
|
||||
if err := l.state.Caches.GTS.ListEntry.Store(entry, func() error {
|
||||
if err := l.state.Caches.DB.ListEntry.Store(entry, func() error {
|
||||
_, err := tx.
|
||||
NewInsert().
|
||||
Model(entry).
|
||||
|
@ -525,7 +525,7 @@ func (l *listDB) DeleteListEntry(ctx context.Context, id string) error {
|
|||
|
||||
defer func() {
|
||||
// Invalidate this list entry upon delete.
|
||||
l.state.Caches.GTS.ListEntry.Invalidate("ID", id)
|
||||
l.state.Caches.DB.ListEntry.Invalidate("ID", id)
|
||||
|
||||
// Invalidate the timeline for the list this entry belongs to.
|
||||
if err := l.state.Timelines.List.RemoveTimeline(ctx, entry.ListID); err != nil {
|
||||
|
|
|
@ -39,7 +39,7 @@ type markerDB struct {
|
|||
*/
|
||||
|
||||
func (m *markerDB) GetMarker(ctx context.Context, accountID string, name gtsmodel.MarkerName) (*gtsmodel.Marker, error) {
|
||||
marker, err := m.state.Caches.GTS.Marker.LoadOne(
|
||||
marker, err := m.state.Caches.DB.Marker.LoadOne(
|
||||
"AccountID,Name",
|
||||
func() (*gtsmodel.Marker, error) {
|
||||
var marker gtsmodel.Marker
|
||||
|
@ -72,7 +72,7 @@ func (m *markerDB) UpdateMarker(ctx context.Context, marker *gtsmodel.Marker) er
|
|||
marker.Version = prevMarker.Version + 1
|
||||
}
|
||||
|
||||
return m.state.Caches.GTS.Marker.Store(marker, func() error {
|
||||
return m.state.Caches.DB.Marker.Store(marker, func() error {
|
||||
if prevMarker == nil {
|
||||
if _, err := m.db.NewInsert().
|
||||
Model(marker).
|
||||
|
|
|
@ -54,7 +54,7 @@ func (m *mediaDB) GetAttachmentByID(ctx context.Context, id string) (*gtsmodel.M
|
|||
|
||||
func (m *mediaDB) GetAttachmentsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.MediaAttachment, error) {
|
||||
// Load all media IDs via cache loader callbacks.
|
||||
media, err := m.state.Caches.GTS.Media.LoadIDs("ID",
|
||||
media, err := m.state.Caches.DB.Media.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.MediaAttachment, error) {
|
||||
// Preallocate expected length of uncached media attachments.
|
||||
|
@ -85,7 +85,7 @@ func (m *mediaDB) GetAttachmentsByIDs(ctx context.Context, ids []string) ([]*gts
|
|||
}
|
||||
|
||||
func (m *mediaDB) getAttachment(ctx context.Context, lookup string, dbQuery func(*gtsmodel.MediaAttachment) error, keyParts ...any) (*gtsmodel.MediaAttachment, error) {
|
||||
return m.state.Caches.GTS.Media.LoadOne(lookup, func() (*gtsmodel.MediaAttachment, error) {
|
||||
return m.state.Caches.DB.Media.LoadOne(lookup, func() (*gtsmodel.MediaAttachment, error) {
|
||||
var attachment gtsmodel.MediaAttachment
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -98,7 +98,7 @@ func (m *mediaDB) getAttachment(ctx context.Context, lookup string, dbQuery func
|
|||
}
|
||||
|
||||
func (m *mediaDB) PutAttachment(ctx context.Context, media *gtsmodel.MediaAttachment) error {
|
||||
return m.state.Caches.GTS.Media.Store(media, func() error {
|
||||
return m.state.Caches.DB.Media.Store(media, func() error {
|
||||
_, err := m.db.NewInsert().Model(media).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -111,7 +111,7 @@ func (m *mediaDB) UpdateAttachment(ctx context.Context, media *gtsmodel.MediaAtt
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return m.state.Caches.GTS.Media.Store(media, func() error {
|
||||
return m.state.Caches.DB.Media.Store(media, func() error {
|
||||
_, err := m.db.NewUpdate().
|
||||
Model(media).
|
||||
Where("? = ?", bun.Ident("media_attachment.id"), media.ID).
|
||||
|
@ -135,7 +135,7 @@ func (m *mediaDB) DeleteAttachment(ctx context.Context, id string) error {
|
|||
}
|
||||
|
||||
// On return, ensure that media with ID is invalidated.
|
||||
defer m.state.Caches.GTS.Media.Invalidate("ID", id)
|
||||
defer m.state.Caches.DB.Media.Invalidate("ID", id)
|
||||
|
||||
// Delete media attachment in new transaction.
|
||||
err = m.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
|
|
|
@ -38,7 +38,7 @@ type mentionDB struct {
|
|||
}
|
||||
|
||||
func (m *mentionDB) GetMention(ctx context.Context, id string) (*gtsmodel.Mention, error) {
|
||||
mention, err := m.state.Caches.GTS.Mention.LoadOne("ID", func() (*gtsmodel.Mention, error) {
|
||||
mention, err := m.state.Caches.DB.Mention.LoadOne("ID", func() (*gtsmodel.Mention, error) {
|
||||
var mention gtsmodel.Mention
|
||||
|
||||
q := m.db.
|
||||
|
@ -66,7 +66,7 @@ func (m *mentionDB) GetMention(ctx context.Context, id string) (*gtsmodel.Mentio
|
|||
|
||||
func (m *mentionDB) GetMentions(ctx context.Context, ids []string) ([]*gtsmodel.Mention, error) {
|
||||
// Load all mention IDs via cache loader callbacks.
|
||||
mentions, err := m.state.Caches.GTS.Mention.LoadIDs("ID",
|
||||
mentions, err := m.state.Caches.DB.Mention.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Mention, error) {
|
||||
// Preallocate expected length of uncached mentions.
|
||||
|
@ -152,14 +152,14 @@ func (m *mentionDB) PopulateMention(ctx context.Context, mention *gtsmodel.Menti
|
|||
}
|
||||
|
||||
func (m *mentionDB) PutMention(ctx context.Context, mention *gtsmodel.Mention) error {
|
||||
return m.state.Caches.GTS.Mention.Store(mention, func() error {
|
||||
return m.state.Caches.DB.Mention.Store(mention, func() error {
|
||||
_, err := m.db.NewInsert().Model(mention).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (m *mentionDB) DeleteMentionByID(ctx context.Context, id string) error {
|
||||
defer m.state.Caches.GTS.Mention.Invalidate("ID", id)
|
||||
defer m.state.Caches.DB.Mention.Invalidate("ID", id)
|
||||
|
||||
// Load mention into cache before attempting a delete,
|
||||
// as we need it cached in order to trigger the invalidate
|
||||
|
|
|
@ -158,7 +158,7 @@ func (m *moveDB) getMove(
|
|||
dbQuery func(*gtsmodel.Move) error,
|
||||
keyParts ...any,
|
||||
) (*gtsmodel.Move, error) {
|
||||
move, err := m.state.Caches.GTS.Move.LoadOne(lookup, func() (*gtsmodel.Move, error) {
|
||||
move, err := m.state.Caches.DB.Move.LoadOne(lookup, func() (*gtsmodel.Move, error) {
|
||||
var move gtsmodel.Move
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -205,7 +205,7 @@ func (m *moveDB) PopulateMove(ctx context.Context, move *gtsmodel.Move) error {
|
|||
}
|
||||
|
||||
func (m *moveDB) PutMove(ctx context.Context, move *gtsmodel.Move) error {
|
||||
return m.state.Caches.GTS.Move.Store(move, func() error {
|
||||
return m.state.Caches.DB.Move.Store(move, func() error {
|
||||
_, err := m.db.
|
||||
NewInsert().
|
||||
Model(move).
|
||||
|
@ -222,7 +222,7 @@ func (m *moveDB) UpdateMove(ctx context.Context, move *gtsmodel.Move, columns ..
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return m.state.Caches.GTS.Move.Store(move, func() error {
|
||||
return m.state.Caches.DB.Move.Store(move, func() error {
|
||||
_, err := m.db.
|
||||
NewUpdate().
|
||||
Model(move).
|
||||
|
@ -234,7 +234,7 @@ func (m *moveDB) UpdateMove(ctx context.Context, move *gtsmodel.Move, columns ..
|
|||
}
|
||||
|
||||
func (m *moveDB) DeleteMoveByID(ctx context.Context, id string) error {
|
||||
defer m.state.Caches.GTS.Move.Invalidate("ID", id)
|
||||
defer m.state.Caches.DB.Move.Invalidate("ID", id)
|
||||
|
||||
_, err := m.db.
|
||||
NewDelete().
|
||||
|
|
|
@ -76,7 +76,7 @@ func (n *notificationDB) GetNotification(
|
|||
|
||||
func (n *notificationDB) getNotification(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Notification) error, keyParts ...any) (*gtsmodel.Notification, error) {
|
||||
// Fetch notification from cache with loader callback
|
||||
notif, err := n.state.Caches.GTS.Notification.LoadOne(lookup, func() (*gtsmodel.Notification, error) {
|
||||
notif, err := n.state.Caches.DB.Notification.LoadOne(lookup, func() (*gtsmodel.Notification, error) {
|
||||
var notif gtsmodel.Notification
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -104,7 +104,7 @@ func (n *notificationDB) getNotification(ctx context.Context, lookup string, dbQ
|
|||
|
||||
func (n *notificationDB) GetNotificationsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Notification, error) {
|
||||
// Load all notif IDs via cache loader callbacks.
|
||||
notifs, err := n.state.Caches.GTS.Notification.LoadIDs("ID",
|
||||
notifs, err := n.state.Caches.DB.Notification.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Notification, error) {
|
||||
// Skip query if everything was cached.
|
||||
|
@ -285,7 +285,7 @@ func (n *notificationDB) GetAccountNotifications(
|
|||
}
|
||||
|
||||
func (n *notificationDB) PutNotification(ctx context.Context, notif *gtsmodel.Notification) error {
|
||||
return n.state.Caches.GTS.Notification.Store(notif, func() error {
|
||||
return n.state.Caches.DB.Notification.Store(notif, func() error {
|
||||
_, err := n.db.NewInsert().Model(notif).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -302,7 +302,7 @@ func (n *notificationDB) DeleteNotificationByID(ctx context.Context, id string)
|
|||
}
|
||||
|
||||
// Invalidate deleted notification by ID.
|
||||
n.state.Caches.GTS.Notification.Invalidate("ID", id)
|
||||
n.state.Caches.DB.Notification.Invalidate("ID", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -337,7 +337,7 @@ func (n *notificationDB) DeleteNotifications(ctx context.Context, types []string
|
|||
}
|
||||
|
||||
// Invalidate all deleted notifications by IDs.
|
||||
n.state.Caches.GTS.Notification.InvalidateIDs("ID", notifIDs)
|
||||
n.state.Caches.DB.Notification.InvalidateIDs("ID", notifIDs)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -354,6 +354,6 @@ func (n *notificationDB) DeleteNotificationsForStatus(ctx context.Context, statu
|
|||
}
|
||||
|
||||
// Invalidate all deleted notifications by IDs.
|
||||
n.state.Caches.GTS.Notification.InvalidateIDs("ID", notifIDs)
|
||||
n.state.Caches.DB.Notification.InvalidateIDs("ID", notifIDs)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func (p *pollDB) GetPollByID(ctx context.Context, id string) (*gtsmodel.Poll, er
|
|||
|
||||
func (p *pollDB) getPoll(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Poll) error, keyParts ...any) (*gtsmodel.Poll, error) {
|
||||
// Fetch poll from database cache with loader callback
|
||||
poll, err := p.state.Caches.GTS.Poll.LoadOne(lookup, func() (*gtsmodel.Poll, error) {
|
||||
poll, err := p.state.Caches.DB.Poll.LoadOne(lookup, func() (*gtsmodel.Poll, error) {
|
||||
var poll gtsmodel.Poll
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -142,7 +142,7 @@ func (p *pollDB) PutPoll(ctx context.Context, poll *gtsmodel.Poll) error {
|
|||
// is non nil and set.
|
||||
poll.CheckVotes()
|
||||
|
||||
return p.state.Caches.GTS.Poll.Store(poll, func() error {
|
||||
return p.state.Caches.DB.Poll.Store(poll, func() error {
|
||||
_, err := p.db.NewInsert().Model(poll).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -153,7 +153,7 @@ func (p *pollDB) UpdatePoll(ctx context.Context, poll *gtsmodel.Poll, cols ...st
|
|||
// is non nil and set.
|
||||
poll.CheckVotes()
|
||||
|
||||
return p.state.Caches.GTS.Poll.Store(poll, func() error {
|
||||
return p.state.Caches.DB.Poll.Store(poll, func() error {
|
||||
return p.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
// Update the status' "updated_at" field.
|
||||
if _, err := tx.NewUpdate().
|
||||
|
@ -186,8 +186,8 @@ func (p *pollDB) DeletePollByID(ctx context.Context, id string) error {
|
|||
}
|
||||
|
||||
// Invalidate poll by ID from cache.
|
||||
p.state.Caches.GTS.Poll.Invalidate("ID", id)
|
||||
p.state.Caches.GTS.PollVoteIDs.Invalidate(id)
|
||||
p.state.Caches.DB.Poll.Invalidate("ID", id)
|
||||
p.state.Caches.DB.PollVoteIDs.Invalidate(id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ func (p *pollDB) GetPollVoteBy(ctx context.Context, pollID string, accountID str
|
|||
|
||||
func (p *pollDB) getPollVote(ctx context.Context, lookup string, dbQuery func(*gtsmodel.PollVote) error, keyParts ...any) (*gtsmodel.PollVote, error) {
|
||||
// Fetch vote from database cache with loader callback
|
||||
vote, err := p.state.Caches.GTS.PollVote.LoadOne(lookup, func() (*gtsmodel.PollVote, error) {
|
||||
vote, err := p.state.Caches.DB.PollVote.LoadOne(lookup, func() (*gtsmodel.PollVote, error) {
|
||||
var vote gtsmodel.PollVote
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -254,7 +254,7 @@ func (p *pollDB) getPollVote(ctx context.Context, lookup string, dbQuery func(*g
|
|||
func (p *pollDB) GetPollVotes(ctx context.Context, pollID string) ([]*gtsmodel.PollVote, error) {
|
||||
|
||||
// Load vote IDs known for given poll ID using loader callback.
|
||||
voteIDs, err := p.state.Caches.GTS.PollVoteIDs.Load(pollID, func() ([]string, error) {
|
||||
voteIDs, err := p.state.Caches.DB.PollVoteIDs.Load(pollID, func() ([]string, error) {
|
||||
var voteIDs []string
|
||||
|
||||
// Vote IDs not in cache, perform DB query!
|
||||
|
@ -271,7 +271,7 @@ func (p *pollDB) GetPollVotes(ctx context.Context, pollID string) ([]*gtsmodel.P
|
|||
}
|
||||
|
||||
// Load all votes from IDs via cache loader callbacks.
|
||||
votes, err := p.state.Caches.GTS.PollVote.LoadIDs("ID",
|
||||
votes, err := p.state.Caches.DB.PollVote.LoadIDs("ID",
|
||||
voteIDs,
|
||||
func(uncached []string) ([]*gtsmodel.PollVote, error) {
|
||||
// Preallocate expected length of uncached votes.
|
||||
|
@ -348,7 +348,7 @@ func (p *pollDB) PopulatePollVote(ctx context.Context, vote *gtsmodel.PollVote)
|
|||
}
|
||||
|
||||
func (p *pollDB) PutPollVote(ctx context.Context, vote *gtsmodel.PollVote) error {
|
||||
return p.state.Caches.GTS.PollVote.Store(vote, func() error {
|
||||
return p.state.Caches.DB.PollVote.Store(vote, func() error {
|
||||
return p.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
// Try insert vote into database.
|
||||
if _, err := tx.NewInsert().
|
||||
|
@ -448,9 +448,9 @@ func (p *pollDB) DeletePollVotes(ctx context.Context, pollID string) error {
|
|||
}
|
||||
|
||||
// Invalidate poll vote and poll entry from caches.
|
||||
p.state.Caches.GTS.Poll.Invalidate("ID", pollID)
|
||||
p.state.Caches.GTS.PollVote.Invalidate("PollID", pollID)
|
||||
p.state.Caches.GTS.PollVoteIDs.Invalidate(pollID)
|
||||
p.state.Caches.DB.Poll.Invalidate("ID", pollID)
|
||||
p.state.Caches.DB.PollVote.Invalidate("PollID", pollID)
|
||||
p.state.Caches.DB.PollVoteIDs.Invalidate(pollID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -523,9 +523,9 @@ func (p *pollDB) DeletePollVoteBy(ctx context.Context, pollID string, accountID
|
|||
}
|
||||
|
||||
// Invalidate poll vote and poll entry from caches.
|
||||
p.state.Caches.GTS.Poll.Invalidate("ID", pollID)
|
||||
p.state.Caches.GTS.PollVote.Invalidate("PollID,AccountID", pollID, accountID)
|
||||
p.state.Caches.GTS.PollVoteIDs.Invalidate(pollID)
|
||||
p.state.Caches.DB.Poll.Invalidate("ID", pollID)
|
||||
p.state.Caches.DB.PollVote.Invalidate("PollID,AccountID", pollID, accountID)
|
||||
p.state.Caches.DB.PollVoteIDs.Invalidate(pollID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ func (r *relationshipDB) GetAccountBlocks(ctx context.Context, accountID string,
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetAccountFollowIDs(ctx context.Context, accountID string, page *paging.Page) ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.GTS.FollowIDs, ">"+accountID, page, func() ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.DB.FollowIDs, ">"+accountID, page, func() ([]string, error) {
|
||||
var followIDs []string
|
||||
|
||||
// Follow IDs not in cache, perform DB query!
|
||||
|
@ -194,7 +194,7 @@ func (r *relationshipDB) GetAccountFollowIDs(ctx context.Context, accountID stri
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetAccountLocalFollowIDs(ctx context.Context, accountID string) ([]string, error) {
|
||||
return r.state.Caches.GTS.FollowIDs.Load("l>"+accountID, func() ([]string, error) {
|
||||
return r.state.Caches.DB.FollowIDs.Load("l>"+accountID, func() ([]string, error) {
|
||||
var followIDs []string
|
||||
|
||||
// Follow IDs not in cache, perform DB query!
|
||||
|
@ -209,7 +209,7 @@ func (r *relationshipDB) GetAccountLocalFollowIDs(ctx context.Context, accountID
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetAccountFollowerIDs(ctx context.Context, accountID string, page *paging.Page) ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.GTS.FollowIDs, "<"+accountID, page, func() ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.DB.FollowIDs, "<"+accountID, page, func() ([]string, error) {
|
||||
var followIDs []string
|
||||
|
||||
// Follow IDs not in cache, perform DB query!
|
||||
|
@ -224,7 +224,7 @@ func (r *relationshipDB) GetAccountFollowerIDs(ctx context.Context, accountID st
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetAccountLocalFollowerIDs(ctx context.Context, accountID string) ([]string, error) {
|
||||
return r.state.Caches.GTS.FollowIDs.Load("l<"+accountID, func() ([]string, error) {
|
||||
return r.state.Caches.DB.FollowIDs.Load("l<"+accountID, func() ([]string, error) {
|
||||
var followIDs []string
|
||||
|
||||
// Follow IDs not in cache, perform DB query!
|
||||
|
@ -239,7 +239,7 @@ func (r *relationshipDB) GetAccountLocalFollowerIDs(ctx context.Context, account
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetAccountFollowRequestIDs(ctx context.Context, accountID string, page *paging.Page) ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.GTS.FollowRequestIDs, ">"+accountID, page, func() ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.DB.FollowRequestIDs, ">"+accountID, page, func() ([]string, error) {
|
||||
var followReqIDs []string
|
||||
|
||||
// Follow request IDs not in cache, perform DB query!
|
||||
|
@ -254,7 +254,7 @@ func (r *relationshipDB) GetAccountFollowRequestIDs(ctx context.Context, account
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetAccountFollowRequestingIDs(ctx context.Context, accountID string, page *paging.Page) ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.GTS.FollowRequestIDs, "<"+accountID, page, func() ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.DB.FollowRequestIDs, "<"+accountID, page, func() ([]string, error) {
|
||||
var followReqIDs []string
|
||||
|
||||
// Follow request IDs not in cache, perform DB query!
|
||||
|
@ -269,7 +269,7 @@ func (r *relationshipDB) GetAccountFollowRequestingIDs(ctx context.Context, acco
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetAccountBlockIDs(ctx context.Context, accountID string, page *paging.Page) ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.GTS.BlockIDs, accountID, page, func() ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.DB.BlockIDs, accountID, page, func() ([]string, error) {
|
||||
var blockIDs []string
|
||||
|
||||
// Block IDs not in cache, perform DB query!
|
||||
|
|
|
@ -102,7 +102,7 @@ func (r *relationshipDB) GetBlock(ctx context.Context, sourceAccountID string, t
|
|||
|
||||
func (r *relationshipDB) GetBlocksByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Block, error) {
|
||||
// Load all blocks IDs via cache loader callbacks.
|
||||
blocks, err := r.state.Caches.GTS.Block.LoadIDs("ID",
|
||||
blocks, err := r.state.Caches.DB.Block.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Block, error) {
|
||||
// Preallocate expected length of uncached blocks.
|
||||
|
@ -149,7 +149,7 @@ func (r *relationshipDB) GetBlocksByIDs(ctx context.Context, ids []string) ([]*g
|
|||
|
||||
func (r *relationshipDB) getBlock(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Block) error, keyParts ...any) (*gtsmodel.Block, error) {
|
||||
// Fetch block from cache with loader callback
|
||||
block, err := r.state.Caches.GTS.Block.LoadOne(lookup, func() (*gtsmodel.Block, error) {
|
||||
block, err := r.state.Caches.DB.Block.LoadOne(lookup, func() (*gtsmodel.Block, error) {
|
||||
var block gtsmodel.Block
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -208,7 +208,7 @@ func (r *relationshipDB) PopulateBlock(ctx context.Context, block *gtsmodel.Bloc
|
|||
}
|
||||
|
||||
func (r *relationshipDB) PutBlock(ctx context.Context, block *gtsmodel.Block) error {
|
||||
return r.state.Caches.GTS.Block.Store(block, func() error {
|
||||
return r.state.Caches.DB.Block.Store(block, func() error {
|
||||
_, err := r.db.NewInsert().Model(block).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -228,7 +228,7 @@ func (r *relationshipDB) DeleteBlockByID(ctx context.Context, id string) error {
|
|||
}
|
||||
|
||||
// Drop this now-cached block on return after delete.
|
||||
defer r.state.Caches.GTS.Block.Invalidate("ID", id)
|
||||
defer r.state.Caches.DB.Block.Invalidate("ID", id)
|
||||
|
||||
// Finally delete block from DB.
|
||||
_, err = r.db.NewDelete().
|
||||
|
@ -252,7 +252,7 @@ func (r *relationshipDB) DeleteBlockByURI(ctx context.Context, uri string) error
|
|||
}
|
||||
|
||||
// Drop this now-cached block on return after delete.
|
||||
defer r.state.Caches.GTS.Block.Invalidate("URI", uri)
|
||||
defer r.state.Caches.DB.Block.Invalidate("URI", uri)
|
||||
|
||||
// Finally delete block from DB.
|
||||
_, err = r.db.NewDelete().
|
||||
|
@ -281,8 +281,8 @@ func (r *relationshipDB) DeleteAccountBlocks(ctx context.Context, accountID stri
|
|||
|
||||
defer func() {
|
||||
// Invalidate all account's incoming / outoing blocks on return.
|
||||
r.state.Caches.GTS.Block.Invalidate("AccountID", accountID)
|
||||
r.state.Caches.GTS.Block.Invalidate("TargetAccountID", accountID)
|
||||
r.state.Caches.DB.Block.Invalidate("AccountID", accountID)
|
||||
r.state.Caches.DB.Block.Invalidate("TargetAccountID", accountID)
|
||||
}()
|
||||
|
||||
// Load all blocks into cache, this *really* isn't great
|
||||
|
|
|
@ -79,7 +79,7 @@ func (r *relationshipDB) GetFollow(ctx context.Context, sourceAccountID string,
|
|||
|
||||
func (r *relationshipDB) GetFollowsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Follow, error) {
|
||||
// Load all follow IDs via cache loader callbacks.
|
||||
follows, err := r.state.Caches.GTS.Follow.LoadIDs("ID",
|
||||
follows, err := r.state.Caches.DB.Follow.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Follow, error) {
|
||||
// Preallocate expected length of uncached follows.
|
||||
|
@ -160,7 +160,7 @@ func (r *relationshipDB) IsMutualFollowing(ctx context.Context, accountID1 strin
|
|||
|
||||
func (r *relationshipDB) getFollow(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Follow) error, keyParts ...any) (*gtsmodel.Follow, error) {
|
||||
// Fetch follow from database cache with loader callback
|
||||
follow, err := r.state.Caches.GTS.Follow.LoadOne(lookup, func() (*gtsmodel.Follow, error) {
|
||||
follow, err := r.state.Caches.DB.Follow.LoadOne(lookup, func() (*gtsmodel.Follow, error) {
|
||||
var follow gtsmodel.Follow
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -219,7 +219,7 @@ func (r *relationshipDB) PopulateFollow(ctx context.Context, follow *gtsmodel.Fo
|
|||
}
|
||||
|
||||
func (r *relationshipDB) PutFollow(ctx context.Context, follow *gtsmodel.Follow) error {
|
||||
return r.state.Caches.GTS.Follow.Store(follow, func() error {
|
||||
return r.state.Caches.DB.Follow.Store(follow, func() error {
|
||||
_, err := r.db.NewInsert().Model(follow).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -232,7 +232,7 @@ func (r *relationshipDB) UpdateFollow(ctx context.Context, follow *gtsmodel.Foll
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return r.state.Caches.GTS.Follow.Store(follow, func() error {
|
||||
return r.state.Caches.DB.Follow.Store(follow, func() error {
|
||||
if _, err := r.db.NewUpdate().
|
||||
Model(follow).
|
||||
Where("? = ?", bun.Ident("follow.id"), follow.ID).
|
||||
|
@ -280,7 +280,7 @@ func (r *relationshipDB) DeleteFollow(ctx context.Context, sourceAccountID strin
|
|||
}
|
||||
|
||||
// Drop this now-cached follow on return after delete.
|
||||
defer r.state.Caches.GTS.Follow.Invalidate("AccountID,TargetAccountID", sourceAccountID, targetAccountID)
|
||||
defer r.state.Caches.DB.Follow.Invalidate("AccountID,TargetAccountID", sourceAccountID, targetAccountID)
|
||||
|
||||
// Finally delete follow from DB.
|
||||
return r.deleteFollow(ctx, follow.ID)
|
||||
|
@ -300,7 +300,7 @@ func (r *relationshipDB) DeleteFollowByID(ctx context.Context, id string) error
|
|||
}
|
||||
|
||||
// Drop this now-cached follow on return after delete.
|
||||
defer r.state.Caches.GTS.Follow.Invalidate("ID", id)
|
||||
defer r.state.Caches.DB.Follow.Invalidate("ID", id)
|
||||
|
||||
// Finally delete follow from DB.
|
||||
return r.deleteFollow(ctx, follow.ID)
|
||||
|
@ -320,7 +320,7 @@ func (r *relationshipDB) DeleteFollowByURI(ctx context.Context, uri string) erro
|
|||
}
|
||||
|
||||
// Drop this now-cached follow on return after delete.
|
||||
defer r.state.Caches.GTS.Follow.Invalidate("URI", uri)
|
||||
defer r.state.Caches.DB.Follow.Invalidate("URI", uri)
|
||||
|
||||
// Finally delete follow from DB.
|
||||
return r.deleteFollow(ctx, follow.ID)
|
||||
|
@ -346,8 +346,8 @@ func (r *relationshipDB) DeleteAccountFollows(ctx context.Context, accountID str
|
|||
|
||||
defer func() {
|
||||
// Invalidate all account's incoming / outoing follows on return.
|
||||
r.state.Caches.GTS.Follow.Invalidate("AccountID", accountID)
|
||||
r.state.Caches.GTS.Follow.Invalidate("TargetAccountID", accountID)
|
||||
r.state.Caches.DB.Follow.Invalidate("AccountID", accountID)
|
||||
r.state.Caches.DB.Follow.Invalidate("TargetAccountID", accountID)
|
||||
}()
|
||||
|
||||
// Load all follows into cache, this *really* isn't great
|
||||
|
|
|
@ -78,7 +78,7 @@ func (r *relationshipDB) GetFollowRequest(ctx context.Context, sourceAccountID s
|
|||
|
||||
func (r *relationshipDB) GetFollowRequestsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.FollowRequest, error) {
|
||||
// Load all follow IDs via cache loader callbacks.
|
||||
follows, err := r.state.Caches.GTS.FollowRequest.LoadIDs("ID",
|
||||
follows, err := r.state.Caches.DB.FollowRequest.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.FollowRequest, error) {
|
||||
// Preallocate expected length of uncached followReqs.
|
||||
|
@ -137,7 +137,7 @@ func (r *relationshipDB) IsFollowRequested(ctx context.Context, sourceAccountID
|
|||
|
||||
func (r *relationshipDB) getFollowRequest(ctx context.Context, lookup string, dbQuery func(*gtsmodel.FollowRequest) error, keyParts ...any) (*gtsmodel.FollowRequest, error) {
|
||||
// Fetch follow request from database cache with loader callback
|
||||
followReq, err := r.state.Caches.GTS.FollowRequest.LoadOne(lookup, func() (*gtsmodel.FollowRequest, error) {
|
||||
followReq, err := r.state.Caches.DB.FollowRequest.LoadOne(lookup, func() (*gtsmodel.FollowRequest, error) {
|
||||
var followReq gtsmodel.FollowRequest
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -196,7 +196,7 @@ func (r *relationshipDB) PopulateFollowRequest(ctx context.Context, follow *gtsm
|
|||
}
|
||||
|
||||
func (r *relationshipDB) PutFollowRequest(ctx context.Context, follow *gtsmodel.FollowRequest) error {
|
||||
return r.state.Caches.GTS.FollowRequest.Store(follow, func() error {
|
||||
return r.state.Caches.DB.FollowRequest.Store(follow, func() error {
|
||||
_, err := r.db.NewInsert().Model(follow).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -209,7 +209,7 @@ func (r *relationshipDB) UpdateFollowRequest(ctx context.Context, followRequest
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return r.state.Caches.GTS.FollowRequest.Store(followRequest, func() error {
|
||||
return r.state.Caches.DB.FollowRequest.Store(followRequest, func() error {
|
||||
if _, err := r.db.NewUpdate().
|
||||
Model(followRequest).
|
||||
Where("? = ?", bun.Ident("follow_request.id"), followRequest.ID).
|
||||
|
@ -242,7 +242,7 @@ func (r *relationshipDB) AcceptFollowRequest(ctx context.Context, sourceAccountI
|
|||
Notify: followReq.Notify,
|
||||
}
|
||||
|
||||
if err := r.state.Caches.GTS.Follow.Store(follow, func() error {
|
||||
if err := r.state.Caches.DB.Follow.Store(follow, func() error {
|
||||
// If the follow already exists, just
|
||||
// replace the URI with the new one.
|
||||
_, err := r.db.
|
||||
|
@ -304,7 +304,7 @@ func (r *relationshipDB) DeleteFollowRequest(ctx context.Context, sourceAccountI
|
|||
}
|
||||
|
||||
// Drop this now-cached follow request on return after delete.
|
||||
defer r.state.Caches.GTS.FollowRequest.Invalidate("AccountID,TargetAccountID", sourceAccountID, targetAccountID)
|
||||
defer r.state.Caches.DB.FollowRequest.Invalidate("AccountID,TargetAccountID", sourceAccountID, targetAccountID)
|
||||
|
||||
// Finally delete followreq from DB.
|
||||
_, err = r.db.NewDelete().
|
||||
|
@ -328,7 +328,7 @@ func (r *relationshipDB) DeleteFollowRequestByID(ctx context.Context, id string)
|
|||
}
|
||||
|
||||
// Drop this now-cached follow request on return after delete.
|
||||
defer r.state.Caches.GTS.FollowRequest.Invalidate("ID", id)
|
||||
defer r.state.Caches.DB.FollowRequest.Invalidate("ID", id)
|
||||
|
||||
// Finally delete followreq from DB.
|
||||
_, err = r.db.NewDelete().
|
||||
|
@ -352,7 +352,7 @@ func (r *relationshipDB) DeleteFollowRequestByURI(ctx context.Context, uri strin
|
|||
}
|
||||
|
||||
// Drop this now-cached follow request on return after delete.
|
||||
defer r.state.Caches.GTS.FollowRequest.Invalidate("URI", uri)
|
||||
defer r.state.Caches.DB.FollowRequest.Invalidate("URI", uri)
|
||||
|
||||
// Finally delete followreq from DB.
|
||||
_, err = r.db.NewDelete().
|
||||
|
@ -382,8 +382,8 @@ func (r *relationshipDB) DeleteAccountFollowRequests(ctx context.Context, accoun
|
|||
|
||||
defer func() {
|
||||
// Invalidate all account's incoming / outoing follow requests on return.
|
||||
r.state.Caches.GTS.FollowRequest.Invalidate("AccountID", accountID)
|
||||
r.state.Caches.GTS.FollowRequest.Invalidate("TargetAccountID", accountID)
|
||||
r.state.Caches.DB.FollowRequest.Invalidate("AccountID", accountID)
|
||||
r.state.Caches.DB.FollowRequest.Invalidate("TargetAccountID", accountID)
|
||||
}()
|
||||
|
||||
// Load all followreqs into cache, this *really* isn't
|
||||
|
|
|
@ -79,7 +79,7 @@ func (r *relationshipDB) GetMute(
|
|||
|
||||
func (r *relationshipDB) getMutesByIDs(ctx context.Context, ids []string) ([]*gtsmodel.UserMute, error) {
|
||||
// Load all mutes IDs via cache loader callbacks.
|
||||
mutes, err := r.state.Caches.GTS.UserMute.LoadIDs("ID",
|
||||
mutes, err := r.state.Caches.DB.UserMute.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.UserMute, error) {
|
||||
// Preallocate expected length of uncached mutes.
|
||||
|
@ -131,7 +131,7 @@ func (r *relationshipDB) getMute(
|
|||
keyParts ...any,
|
||||
) (*gtsmodel.UserMute, error) {
|
||||
// Fetch mute from cache with loader callback
|
||||
mute, err := r.state.Caches.GTS.UserMute.LoadOne(lookup, func() (*gtsmodel.UserMute, error) {
|
||||
mute, err := r.state.Caches.DB.UserMute.LoadOne(lookup, func() (*gtsmodel.UserMute, error) {
|
||||
var mute gtsmodel.UserMute
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -190,7 +190,7 @@ func (r *relationshipDB) populateMute(ctx context.Context, mute *gtsmodel.UserMu
|
|||
}
|
||||
|
||||
func (r *relationshipDB) PutMute(ctx context.Context, mute *gtsmodel.UserMute) error {
|
||||
return r.state.Caches.GTS.UserMute.Store(mute, func() error {
|
||||
return r.state.Caches.DB.UserMute.Store(mute, func() error {
|
||||
_, err := NewUpsert(r.db).Model(mute).Constraint("id").Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -210,7 +210,7 @@ func (r *relationshipDB) DeleteMuteByID(ctx context.Context, id string) error {
|
|||
}
|
||||
|
||||
// Drop this now-cached mute on return after delete.
|
||||
defer r.state.Caches.GTS.UserMute.Invalidate("ID", id)
|
||||
defer r.state.Caches.DB.UserMute.Invalidate("ID", id)
|
||||
|
||||
// Finally delete mute from DB.
|
||||
_, err = r.db.NewDelete().
|
||||
|
@ -239,8 +239,8 @@ func (r *relationshipDB) DeleteAccountMutes(ctx context.Context, accountID strin
|
|||
|
||||
defer func() {
|
||||
// Invalidate all account's incoming / outoing mutes on return.
|
||||
r.state.Caches.GTS.UserMute.Invalidate("AccountID", accountID)
|
||||
r.state.Caches.GTS.UserMute.Invalidate("TargetAccountID", accountID)
|
||||
r.state.Caches.DB.UserMute.Invalidate("AccountID", accountID)
|
||||
r.state.Caches.DB.UserMute.Invalidate("TargetAccountID", accountID)
|
||||
}()
|
||||
|
||||
// Load all mutes into cache, this *really* isn't great
|
||||
|
@ -272,7 +272,7 @@ func (r *relationshipDB) GetAccountMutes(
|
|||
}
|
||||
|
||||
func (r *relationshipDB) getAccountMuteIDs(ctx context.Context, accountID string, page *paging.Page) ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.GTS.UserMuteIDs, accountID, page, func() ([]string, error) {
|
||||
return loadPagedIDs(&r.state.Caches.DB.UserMuteIDs, accountID, page, func() ([]string, error) {
|
||||
var muteIDs []string
|
||||
|
||||
// Mute IDs not in cache. Perform DB query.
|
||||
|
|
|
@ -44,7 +44,7 @@ func (r *relationshipDB) GetNote(ctx context.Context, sourceAccountID string, ta
|
|||
|
||||
func (r *relationshipDB) getNote(ctx context.Context, lookup string, dbQuery func(*gtsmodel.AccountNote) error, keyParts ...any) (*gtsmodel.AccountNote, error) {
|
||||
// Fetch note from cache with loader callback
|
||||
note, err := r.state.Caches.GTS.AccountNote.LoadOne(lookup, func() (*gtsmodel.AccountNote, error) {
|
||||
note, err := r.state.Caches.DB.AccountNote.LoadOne(lookup, func() (*gtsmodel.AccountNote, error) {
|
||||
var note gtsmodel.AccountNote
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -105,7 +105,7 @@ func (r *relationshipDB) PopulateNote(ctx context.Context, note *gtsmodel.Accoun
|
|||
|
||||
func (r *relationshipDB) PutNote(ctx context.Context, note *gtsmodel.AccountNote) error {
|
||||
note.UpdatedAt = time.Now()
|
||||
return r.state.Caches.GTS.AccountNote.Store(note, func() error {
|
||||
return r.state.Caches.DB.AccountNote.Store(note, func() error {
|
||||
_, err := r.db.
|
||||
NewInsert().
|
||||
Model(note).
|
||||
|
|
|
@ -147,7 +147,7 @@ func (r *reportDB) GetReports(ctx context.Context, resolved *bool, accountID str
|
|||
|
||||
func (r *reportDB) getReport(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Report) error, keyParts ...any) (*gtsmodel.Report, error) {
|
||||
// Fetch report from database cache with loader callback
|
||||
report, err := r.state.Caches.GTS.Report.LoadOne(lookup, func() (*gtsmodel.Report, error) {
|
||||
report, err := r.state.Caches.DB.Report.LoadOne(lookup, func() (*gtsmodel.Report, error) {
|
||||
var report gtsmodel.Report
|
||||
|
||||
// Not cached! Perform database query
|
||||
|
@ -242,7 +242,7 @@ func (r *reportDB) PopulateReport(ctx context.Context, report *gtsmodel.Report)
|
|||
}
|
||||
|
||||
func (r *reportDB) PutReport(ctx context.Context, report *gtsmodel.Report) error {
|
||||
return r.state.Caches.GTS.Report.Store(report, func() error {
|
||||
return r.state.Caches.DB.Report.Store(report, func() error {
|
||||
_, err := r.db.NewInsert().Model(report).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -264,12 +264,12 @@ func (r *reportDB) UpdateReport(ctx context.Context, report *gtsmodel.Report, co
|
|||
return nil, err
|
||||
}
|
||||
|
||||
r.state.Caches.GTS.Report.Invalidate("ID", report.ID)
|
||||
r.state.Caches.DB.Report.Invalidate("ID", report.ID)
|
||||
return report, nil
|
||||
}
|
||||
|
||||
func (r *reportDB) DeleteReportByID(ctx context.Context, id string) error {
|
||||
defer r.state.Caches.GTS.Report.Invalidate("ID", id)
|
||||
defer r.state.Caches.DB.Report.Invalidate("ID", id)
|
||||
|
||||
// Load status into cache before attempting a delete,
|
||||
// as we need it cached in order to trigger the invalidate
|
||||
|
|
|
@ -125,7 +125,7 @@ func (r *ruleDB) PutRule(ctx context.Context, rule *gtsmodel.Rule) error {
|
|||
}
|
||||
|
||||
// invalidate cached local instance response, so it gets updated with the new rules
|
||||
r.state.Caches.GTS.Instance.Invalidate("Domain", config.GetHost())
|
||||
r.state.Caches.DB.Instance.Invalidate("Domain", config.GetHost())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ func (r *ruleDB) UpdateRule(ctx context.Context, rule *gtsmodel.Rule) (*gtsmodel
|
|||
}
|
||||
|
||||
// invalidate cached local instance response, so it gets updated with the new rules
|
||||
r.state.Caches.GTS.Instance.Invalidate("Domain", config.GetHost())
|
||||
r.state.Caches.DB.Instance.Invalidate("Domain", config.GetHost())
|
||||
|
||||
return rule, nil
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func (s *statusDB) GetStatusByID(ctx context.Context, id string) (*gtsmodel.Stat
|
|||
|
||||
func (s *statusDB) GetStatusesByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Status, error) {
|
||||
// Load all input status IDs via cache loader callback.
|
||||
statuses, err := s.state.Caches.GTS.Status.LoadIDs("ID",
|
||||
statuses, err := s.state.Caches.DB.Status.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Status, error) {
|
||||
// Preallocate expected length of uncached statuses.
|
||||
|
@ -151,7 +151,7 @@ func (s *statusDB) GetStatusBoost(ctx context.Context, boostOfID string, byAccou
|
|||
|
||||
func (s *statusDB) getStatus(ctx context.Context, lookup string, dbQuery func(*gtsmodel.Status) error, keyParts ...any) (*gtsmodel.Status, error) {
|
||||
// Fetch status from database cache with loader callback
|
||||
status, err := s.state.Caches.GTS.Status.LoadOne(lookup, func() (*gtsmodel.Status, error) {
|
||||
status, err := s.state.Caches.DB.Status.LoadOne(lookup, func() (*gtsmodel.Status, error) {
|
||||
var status gtsmodel.Status
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -313,7 +313,7 @@ func (s *statusDB) PopulateStatus(ctx context.Context, status *gtsmodel.Status)
|
|||
}
|
||||
|
||||
func (s *statusDB) PutStatus(ctx context.Context, status *gtsmodel.Status) error {
|
||||
return s.state.Caches.GTS.Status.Store(status, func() error {
|
||||
return s.state.Caches.DB.Status.Store(status, func() error {
|
||||
// It is safe to run this database transaction within cache.Store
|
||||
// as the cache does not attempt a mutex lock until AFTER hook.
|
||||
//
|
||||
|
@ -397,7 +397,7 @@ func (s *statusDB) UpdateStatus(ctx context.Context, status *gtsmodel.Status, co
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return s.state.Caches.GTS.Status.Store(status, func() error {
|
||||
return s.state.Caches.DB.Status.Store(status, func() error {
|
||||
// It is safe to run this database transaction within cache.Store
|
||||
// as the cache does not attempt a mutex lock until AFTER hook.
|
||||
//
|
||||
|
@ -494,7 +494,7 @@ func (s *statusDB) DeleteStatusByID(ctx context.Context, id string) error {
|
|||
}
|
||||
|
||||
// On return ensure status invalidated from cache.
|
||||
defer s.state.Caches.GTS.Status.Invalidate("ID", id)
|
||||
defer s.state.Caches.DB.Status.Invalidate("ID", id)
|
||||
|
||||
return s.db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
// delete links between this status and any emojis it uses
|
||||
|
@ -621,7 +621,7 @@ func (s *statusDB) CountStatusReplies(ctx context.Context, statusID string) (int
|
|||
}
|
||||
|
||||
func (s *statusDB) getStatusReplyIDs(ctx context.Context, statusID string) ([]string, error) {
|
||||
return s.state.Caches.GTS.InReplyToIDs.Load(statusID, func() ([]string, error) {
|
||||
return s.state.Caches.DB.InReplyToIDs.Load(statusID, func() ([]string, error) {
|
||||
var statusIDs []string
|
||||
|
||||
// Status reply IDs not in cache, perform DB query!
|
||||
|
@ -665,7 +665,7 @@ func (s *statusDB) CountStatusBoosts(ctx context.Context, statusID string) (int,
|
|||
}
|
||||
|
||||
func (s *statusDB) getStatusBoostIDs(ctx context.Context, statusID string) ([]string, error) {
|
||||
return s.state.Caches.GTS.BoostOfIDs.Load(statusID, func() ([]string, error) {
|
||||
return s.state.Caches.DB.BoostOfIDs.Load(statusID, func() ([]string, error) {
|
||||
var statusIDs []string
|
||||
|
||||
// Status boost IDs not in cache, perform DB query!
|
||||
|
|
|
@ -70,7 +70,7 @@ func (s *statusBookmarkDB) GetStatusBookmark(ctx context.Context, accountID stri
|
|||
|
||||
func (s *statusBookmarkDB) GetStatusBookmarksByIDs(ctx context.Context, ids []string) ([]*gtsmodel.StatusBookmark, error) {
|
||||
// Load all input bookmark IDs via cache loader callback.
|
||||
bookmarks, err := s.state.Caches.GTS.StatusBookmark.LoadIDs("ID",
|
||||
bookmarks, err := s.state.Caches.DB.StatusBookmark.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.StatusBookmark, error) {
|
||||
// Preallocate expected length of uncached bookmarks.
|
||||
|
@ -125,7 +125,7 @@ func (s *statusBookmarkDB) IsStatusBookmarkedBy(ctx context.Context, accountID s
|
|||
|
||||
func (s *statusBookmarkDB) getStatusBookmark(ctx context.Context, lookup string, dbQuery func(*gtsmodel.StatusBookmark) error, keyParts ...any) (*gtsmodel.StatusBookmark, error) {
|
||||
// Fetch bookmark from database cache with loader callback.
|
||||
bookmark, err := s.state.Caches.GTS.StatusBookmark.LoadOne(lookup, func() (*gtsmodel.StatusBookmark, error) {
|
||||
bookmark, err := s.state.Caches.DB.StatusBookmark.LoadOne(lookup, func() (*gtsmodel.StatusBookmark, error) {
|
||||
var bookmark gtsmodel.StatusBookmark
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -231,7 +231,7 @@ func (s *statusBookmarkDB) GetStatusBookmarks(ctx context.Context, accountID str
|
|||
}
|
||||
|
||||
func (s *statusBookmarkDB) getStatusBookmarkIDs(ctx context.Context, statusID string) ([]string, error) {
|
||||
return s.state.Caches.GTS.StatusBookmarkIDs.Load(statusID, func() ([]string, error) {
|
||||
return s.state.Caches.DB.StatusBookmarkIDs.Load(statusID, func() ([]string, error) {
|
||||
var bookmarkIDs []string
|
||||
|
||||
// Bookmark IDs not cached,
|
||||
|
@ -250,7 +250,7 @@ func (s *statusBookmarkDB) getStatusBookmarkIDs(ctx context.Context, statusID st
|
|||
}
|
||||
|
||||
func (s *statusBookmarkDB) PutStatusBookmark(ctx context.Context, bookmark *gtsmodel.StatusBookmark) error {
|
||||
return s.state.Caches.GTS.StatusBookmark.Store(bookmark, func() error {
|
||||
return s.state.Caches.DB.StatusBookmark.Store(bookmark, func() error {
|
||||
_, err := s.db.NewInsert().Model(bookmark).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -265,7 +265,7 @@ func (s *statusBookmarkDB) DeleteStatusBookmarkByID(ctx context.Context, id stri
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.state.Caches.GTS.StatusBookmark.Invalidate("ID", id)
|
||||
s.state.Caches.DB.StatusBookmark.Invalidate("ID", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -280,12 +280,12 @@ func (s *statusBookmarkDB) DeleteStatusBookmarks(ctx context.Context, targetAcco
|
|||
|
||||
if targetAccountID != "" {
|
||||
q = q.Where("? = ?", bun.Ident("status_bookmark.target_account_id"), targetAccountID)
|
||||
defer s.state.Caches.GTS.StatusBookmark.Invalidate("TargetAccountID", targetAccountID)
|
||||
defer s.state.Caches.DB.StatusBookmark.Invalidate("TargetAccountID", targetAccountID)
|
||||
}
|
||||
|
||||
if originAccountID != "" {
|
||||
q = q.Where("? = ?", bun.Ident("status_bookmark.account_id"), originAccountID)
|
||||
defer s.state.Caches.GTS.StatusBookmark.Invalidate("AccountID", originAccountID)
|
||||
defer s.state.Caches.DB.StatusBookmark.Invalidate("AccountID", originAccountID)
|
||||
}
|
||||
|
||||
if _, err := q.Exec(ctx); err != nil {
|
||||
|
@ -293,11 +293,11 @@ func (s *statusBookmarkDB) DeleteStatusBookmarks(ctx context.Context, targetAcco
|
|||
}
|
||||
|
||||
if targetAccountID != "" {
|
||||
s.state.Caches.GTS.StatusBookmark.Invalidate("TargetAccountID", targetAccountID)
|
||||
s.state.Caches.DB.StatusBookmark.Invalidate("TargetAccountID", targetAccountID)
|
||||
}
|
||||
|
||||
if originAccountID != "" {
|
||||
s.state.Caches.GTS.StatusBookmark.Invalidate("AccountID", originAccountID)
|
||||
s.state.Caches.DB.StatusBookmark.Invalidate("AccountID", originAccountID)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -311,6 +311,6 @@ func (s *statusBookmarkDB) DeleteStatusBookmarksForStatus(ctx context.Context, s
|
|||
if _, err := q.Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
s.state.Caches.GTS.StatusBookmark.Invalidate("StatusID", statusID)
|
||||
s.state.Caches.DB.StatusBookmark.Invalidate("StatusID", statusID)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ func (s *statusFaveDB) GetStatusFaveByURI(ctx context.Context, uri string) (*gts
|
|||
|
||||
func (s *statusFaveDB) getStatusFave(ctx context.Context, lookup string, dbQuery func(*gtsmodel.StatusFave) error, keyParts ...any) (*gtsmodel.StatusFave, error) {
|
||||
// Fetch status fave from database cache with loader callback
|
||||
fave, err := s.state.Caches.GTS.StatusFave.LoadOne(lookup, func() (*gtsmodel.StatusFave, error) {
|
||||
fave, err := s.state.Caches.DB.StatusFave.LoadOne(lookup, func() (*gtsmodel.StatusFave, error) {
|
||||
var fave gtsmodel.StatusFave
|
||||
|
||||
// Not cached! Perform database query.
|
||||
|
@ -130,7 +130,7 @@ func (s *statusFaveDB) GetStatusFaves(ctx context.Context, statusID string) ([]*
|
|||
}
|
||||
|
||||
// Load all fave IDs via cache loader callbacks.
|
||||
faves, err := s.state.Caches.GTS.StatusFave.LoadIDs("ID",
|
||||
faves, err := s.state.Caches.DB.StatusFave.LoadIDs("ID",
|
||||
faveIDs,
|
||||
func(uncached []string) ([]*gtsmodel.StatusFave, error) {
|
||||
// Preallocate expected length of uncached faves.
|
||||
|
@ -189,7 +189,7 @@ func (s *statusFaveDB) CountStatusFaves(ctx context.Context, statusID string) (i
|
|||
}
|
||||
|
||||
func (s *statusFaveDB) getStatusFaveIDs(ctx context.Context, statusID string) ([]string, error) {
|
||||
return s.state.Caches.GTS.StatusFaveIDs.Load(statusID, func() ([]string, error) {
|
||||
return s.state.Caches.DB.StatusFaveIDs.Load(statusID, func() ([]string, error) {
|
||||
var faveIDs []string
|
||||
|
||||
// Status fave IDs not in cache, perform DB query!
|
||||
|
@ -249,7 +249,7 @@ func (s *statusFaveDB) PopulateStatusFave(ctx context.Context, statusFave *gtsmo
|
|||
}
|
||||
|
||||
func (s *statusFaveDB) PutStatusFave(ctx context.Context, fave *gtsmodel.StatusFave) error {
|
||||
return s.state.Caches.GTS.StatusFave.Store(fave, func() error {
|
||||
return s.state.Caches.DB.StatusFave.Store(fave, func() error {
|
||||
_, err := s.db.
|
||||
NewInsert().
|
||||
Model(fave).
|
||||
|
@ -267,7 +267,7 @@ func (s *statusFaveDB) UpdateStatusFave(ctx context.Context, fave *gtsmodel.Stat
|
|||
}
|
||||
|
||||
// Update the status fave model in the database.
|
||||
return s.state.Caches.GTS.StatusFave.Store(fave, func() error {
|
||||
return s.state.Caches.DB.StatusFave.Store(fave, func() error {
|
||||
_, err := s.db.
|
||||
NewUpdate().
|
||||
Model(fave).
|
||||
|
@ -298,10 +298,10 @@ func (s *statusFaveDB) DeleteStatusFaveByID(ctx context.Context, id string) erro
|
|||
|
||||
if statusID != "" {
|
||||
// Invalidate any cached status faves for this status.
|
||||
s.state.Caches.GTS.StatusFave.Invalidate("ID", id)
|
||||
s.state.Caches.DB.StatusFave.Invalidate("ID", id)
|
||||
|
||||
// Invalidate any cached status fave IDs for this status.
|
||||
s.state.Caches.GTS.StatusFaveIDs.Invalidate(statusID)
|
||||
s.state.Caches.DB.StatusFaveIDs.Invalidate(statusID)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -342,10 +342,10 @@ func (s *statusFaveDB) DeleteStatusFaves(ctx context.Context, targetAccountID st
|
|||
statusIDs = util.Deduplicate(statusIDs)
|
||||
|
||||
// Invalidate any cached status faves for this status ID.
|
||||
s.state.Caches.GTS.StatusFave.InvalidateIDs("ID", statusIDs)
|
||||
s.state.Caches.DB.StatusFave.InvalidateIDs("ID", statusIDs)
|
||||
|
||||
// Invalidate any cached status fave IDs for this status ID.
|
||||
s.state.Caches.GTS.StatusFaveIDs.Invalidate(statusIDs...)
|
||||
s.state.Caches.DB.StatusFaveIDs.Invalidate(statusIDs...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -360,10 +360,10 @@ func (s *statusFaveDB) DeleteStatusFavesForStatus(ctx context.Context, statusID
|
|||
}
|
||||
|
||||
// Invalidate any cached status faves for this status.
|
||||
s.state.Caches.GTS.StatusFave.Invalidate("ID", statusID)
|
||||
s.state.Caches.DB.StatusFave.Invalidate("ID", statusID)
|
||||
|
||||
// Invalidate any cached status fave IDs for this status.
|
||||
s.state.Caches.GTS.StatusFaveIDs.Invalidate(statusID)
|
||||
s.state.Caches.DB.StatusFaveIDs.Invalidate(statusID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ type tagDB struct {
|
|||
}
|
||||
|
||||
func (t *tagDB) GetTag(ctx context.Context, id string) (*gtsmodel.Tag, error) {
|
||||
return t.state.Caches.GTS.Tag.LoadOne("ID", func() (*gtsmodel.Tag, error) {
|
||||
return t.state.Caches.DB.Tag.LoadOne("ID", func() (*gtsmodel.Tag, error) {
|
||||
var tag gtsmodel.Tag
|
||||
|
||||
q := t.db.
|
||||
|
@ -54,7 +54,7 @@ func (t *tagDB) GetTagByName(ctx context.Context, name string) (*gtsmodel.Tag, e
|
|||
name = strings.TrimSpace(name)
|
||||
name = strings.ToLower(name)
|
||||
|
||||
return t.state.Caches.GTS.Tag.LoadOne("Name", func() (*gtsmodel.Tag, error) {
|
||||
return t.state.Caches.DB.Tag.LoadOne("Name", func() (*gtsmodel.Tag, error) {
|
||||
var tag gtsmodel.Tag
|
||||
|
||||
q := t.db.
|
||||
|
@ -72,7 +72,7 @@ func (t *tagDB) GetTagByName(ctx context.Context, name string) (*gtsmodel.Tag, e
|
|||
|
||||
func (t *tagDB) GetTags(ctx context.Context, ids []string) ([]*gtsmodel.Tag, error) {
|
||||
// Load all tag IDs via cache loader callbacks.
|
||||
tags, err := t.state.Caches.GTS.Tag.LoadIDs("ID",
|
||||
tags, err := t.state.Caches.DB.Tag.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Tag, error) {
|
||||
// Preallocate expected length of uncached tags.
|
||||
|
@ -115,7 +115,7 @@ func (t *tagDB) PutTag(ctx context.Context, tag *gtsmodel.Tag) error {
|
|||
t2.Name = strings.ToLower(t2.Name)
|
||||
|
||||
// Insert the copy.
|
||||
if err := t.state.Caches.GTS.Tag.Store(t2, func() error {
|
||||
if err := t.state.Caches.DB.Tag.Store(t2, func() error {
|
||||
_, err := t.db.NewInsert().Model(t2).Exec(ctx)
|
||||
return err
|
||||
}); err != nil {
|
||||
|
|
|
@ -42,7 +42,7 @@ func (t *threadDB) PutThread(ctx context.Context, thread *gtsmodel.Thread) error
|
|||
}
|
||||
|
||||
func (t *threadDB) GetThreadMute(ctx context.Context, id string) (*gtsmodel.ThreadMute, error) {
|
||||
return t.state.Caches.GTS.ThreadMute.LoadOne("ID", func() (*gtsmodel.ThreadMute, error) {
|
||||
return t.state.Caches.DB.ThreadMute.LoadOne("ID", func() (*gtsmodel.ThreadMute, error) {
|
||||
var threadMute gtsmodel.ThreadMute
|
||||
|
||||
q := t.db.
|
||||
|
@ -63,7 +63,7 @@ func (t *threadDB) GetThreadMutedByAccount(
|
|||
threadID string,
|
||||
accountID string,
|
||||
) (*gtsmodel.ThreadMute, error) {
|
||||
return t.state.Caches.GTS.ThreadMute.LoadOne("ThreadID,AccountID", func() (*gtsmodel.ThreadMute, error) {
|
||||
return t.state.Caches.DB.ThreadMute.LoadOne("ThreadID,AccountID", func() (*gtsmodel.ThreadMute, error) {
|
||||
var threadMute gtsmodel.ThreadMute
|
||||
|
||||
q := t.db.
|
||||
|
@ -98,7 +98,7 @@ func (t *threadDB) IsThreadMutedByAccount(
|
|||
}
|
||||
|
||||
func (t *threadDB) PutThreadMute(ctx context.Context, threadMute *gtsmodel.ThreadMute) error {
|
||||
return t.state.Caches.GTS.ThreadMute.Store(threadMute, func() error {
|
||||
return t.state.Caches.DB.ThreadMute.Store(threadMute, func() error {
|
||||
_, err := t.db.NewInsert().Model(threadMute).Exec(ctx)
|
||||
return err
|
||||
})
|
||||
|
@ -112,6 +112,6 @@ func (t *threadDB) DeleteThreadMute(ctx context.Context, id string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
t.state.Caches.GTS.ThreadMute.Invalidate("ID", id)
|
||||
t.state.Caches.DB.ThreadMute.Invalidate("ID", id)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ type tombstoneDB struct {
|
|||
}
|
||||
|
||||
func (t *tombstoneDB) GetTombstoneByURI(ctx context.Context, uri string) (*gtsmodel.Tombstone, error) {
|
||||
return t.state.Caches.GTS.Tombstone.LoadOne("URI", func() (*gtsmodel.Tombstone, error) {
|
||||
return t.state.Caches.DB.Tombstone.LoadOne("URI", func() (*gtsmodel.Tombstone, error) {
|
||||
var tomb gtsmodel.Tombstone
|
||||
|
||||
q := t.db.
|
||||
|
@ -57,7 +57,7 @@ func (t *tombstoneDB) TombstoneExistsWithURI(ctx context.Context, uri string) (b
|
|||
}
|
||||
|
||||
func (t *tombstoneDB) PutTombstone(ctx context.Context, tombstone *gtsmodel.Tombstone) error {
|
||||
return t.state.Caches.GTS.Tombstone.Store(tombstone, func() error {
|
||||
return t.state.Caches.DB.Tombstone.Store(tombstone, func() error {
|
||||
_, err := t.db.
|
||||
NewInsert().
|
||||
Model(tombstone).
|
||||
|
@ -67,7 +67,7 @@ func (t *tombstoneDB) PutTombstone(ctx context.Context, tombstone *gtsmodel.Tomb
|
|||
}
|
||||
|
||||
func (t *tombstoneDB) DeleteTombstone(ctx context.Context, id string) error {
|
||||
defer t.state.Caches.GTS.Tombstone.Invalidate("ID", id)
|
||||
defer t.state.Caches.DB.Tombstone.Invalidate("ID", id)
|
||||
|
||||
// Delete tombstone from DB.
|
||||
_, err := t.db.NewDelete().
|
||||
|
|
|
@ -116,7 +116,7 @@ func (u *userDB) GetUserByConfirmationToken(ctx context.Context, token string) (
|
|||
|
||||
func (u *userDB) getUser(ctx context.Context, lookup string, dbQuery func(*gtsmodel.User) error, keyParts ...any) (*gtsmodel.User, error) {
|
||||
// Fetch user from database cache with loader callback.
|
||||
user, err := u.state.Caches.GTS.User.LoadOne(lookup, func() (*gtsmodel.User, error) {
|
||||
user, err := u.state.Caches.DB.User.LoadOne(lookup, func() (*gtsmodel.User, error) {
|
||||
var user gtsmodel.User
|
||||
|
||||
// Not cached! perform database query.
|
||||
|
@ -179,7 +179,7 @@ func (u *userDB) GetAllUsers(ctx context.Context) ([]*gtsmodel.User, error) {
|
|||
}
|
||||
|
||||
func (u *userDB) PutUser(ctx context.Context, user *gtsmodel.User) error {
|
||||
return u.state.Caches.GTS.User.Store(user, func() error {
|
||||
return u.state.Caches.DB.User.Store(user, func() error {
|
||||
_, err := u.db.
|
||||
NewInsert().
|
||||
Model(user).
|
||||
|
@ -197,7 +197,7 @@ func (u *userDB) UpdateUser(ctx context.Context, user *gtsmodel.User, columns ..
|
|||
columns = append(columns, "updated_at")
|
||||
}
|
||||
|
||||
return u.state.Caches.GTS.User.Store(user, func() error {
|
||||
return u.state.Caches.DB.User.Store(user, func() error {
|
||||
_, err := u.db.
|
||||
NewUpdate().
|
||||
Model(user).
|
||||
|
@ -209,7 +209,7 @@ func (u *userDB) UpdateUser(ctx context.Context, user *gtsmodel.User, columns ..
|
|||
}
|
||||
|
||||
func (u *userDB) DeleteUserByID(ctx context.Context, userID string) error {
|
||||
defer u.state.Caches.GTS.User.Invalidate("ID", userID)
|
||||
defer u.state.Caches.DB.User.Invalidate("ID", userID)
|
||||
|
||||
// Load user into cache before attempting a delete,
|
||||
// as we need it cached in order to trigger the invalidate
|
||||
|
|
|
@ -80,7 +80,7 @@ func (suite *AnnounceTestSuite) TestAnnounceTwice() {
|
|||
// Insert the boost-of status into the
|
||||
// DB cache to emulate processor handling
|
||||
boost.ID, _ = id.NewULIDFromTime(boost.CreatedAt)
|
||||
suite.state.Caches.GTS.Status.Put(boost)
|
||||
suite.state.Caches.DB.Status.Put(boost)
|
||||
|
||||
// only the URI will be set for the boosted status
|
||||
// because it still needs to be dereferenced
|
||||
|
|
|
@ -36,7 +36,7 @@ import (
|
|||
func (t *transport) webfingerURLFor(targetDomain string) (string, bool) {
|
||||
url := "https://" + targetDomain + "/.well-known/webfinger"
|
||||
|
||||
wc := t.controller.state.Caches.GTS.Webfinger
|
||||
wc := t.controller.state.Caches.Webfinger
|
||||
|
||||
// We're doing the manual locking/unlocking here to be able to
|
||||
// safely call Cache.Get instead of Get, as the latter updates the
|
||||
|
@ -95,7 +95,7 @@ func (t *transport) Finger(ctx context.Context, targetUsername string, targetDom
|
|||
// If we got a response we consider successful on a cached URL, i.e one set
|
||||
// by us later on when a host-meta based webfinger request succeeded, set it
|
||||
// again here to renew the TTL
|
||||
t.controller.state.Caches.GTS.Webfinger.Set(targetDomain, url)
|
||||
t.controller.state.Caches.Webfinger.Set(targetDomain, url)
|
||||
}
|
||||
|
||||
if rsp.StatusCode == http.StatusGone {
|
||||
|
@ -159,7 +159,7 @@ func (t *transport) Finger(ctx context.Context, targetUsername string, targetDom
|
|||
// we asked for is gone. This means the endpoint itself is valid and we should
|
||||
// cache it for future queries to the same domain
|
||||
if rsp.StatusCode == http.StatusGone {
|
||||
t.controller.state.Caches.GTS.Webfinger.Set(targetDomain, host)
|
||||
t.controller.state.Caches.Webfinger.Set(targetDomain, host)
|
||||
return nil, fmt.Errorf("account has been deleted/is gone")
|
||||
}
|
||||
// We've reached the end of the line here, both the original request
|
||||
|
@ -170,7 +170,7 @@ func (t *transport) Finger(ctx context.Context, targetUsername string, targetDom
|
|||
// Set the URL in cache here, since host-meta told us this should be the
|
||||
// valid one, it's different from the default and our request to it did
|
||||
// not fail in any manner
|
||||
t.controller.state.Caches.GTS.Webfinger.Set(targetDomain, host)
|
||||
t.controller.state.Caches.Webfinger.Set(targetDomain, host)
|
||||
|
||||
return io.ReadAll(rsp.Body)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ type FingerTestSuite struct {
|
|||
}
|
||||
|
||||
func (suite *FingerTestSuite) TestFinger() {
|
||||
wc := suite.state.Caches.GTS.Webfinger
|
||||
wc := suite.state.Caches.Webfinger
|
||||
suite.Equal(0, wc.Len(), "expect webfinger cache to be empty")
|
||||
|
||||
_, err := suite.transport.Finger(context.TODO(), "brand_new_person", "unknown-instance.com")
|
||||
|
@ -43,7 +43,7 @@ func (suite *FingerTestSuite) TestFinger() {
|
|||
}
|
||||
|
||||
func (suite *FingerTestSuite) TestFingerWithHostMeta() {
|
||||
wc := suite.state.Caches.GTS.Webfinger
|
||||
wc := suite.state.Caches.Webfinger
|
||||
suite.Equal(0, wc.Len(), "expect webfinger cache to be empty")
|
||||
|
||||
_, err := suite.transport.Finger(context.TODO(), "someone", "misconfigured-instance.com")
|
||||
|
@ -60,7 +60,7 @@ func (suite *FingerTestSuite) TestFingerWithHostMetaCacheStrategy() {
|
|||
suite.T().Skip("this test is flaky on CI for as of yet unknown reasons")
|
||||
}
|
||||
|
||||
wc := suite.state.Caches.GTS.Webfinger
|
||||
wc := suite.state.Caches.Webfinger
|
||||
|
||||
// Reset the sweep frequency so nothing interferes with the test
|
||||
wc.Stop()
|
||||
|
|
|
@ -631,7 +631,7 @@ func (suite *ASToInternalTestSuite) TestParseHonkAccount() {
|
|||
suite.False(*dbAcct.Discoverable)
|
||||
|
||||
// Clear caches.
|
||||
suite.state.Caches.GTS = cache.GTSCaches{}
|
||||
suite.state.Caches.DB = cache.DBCaches{}
|
||||
suite.state.Caches.Init()
|
||||
|
||||
dbAcct, err = suite.db.GetAccountByID(ctx, acct.ID)
|
||||
|
|
Loading…
Reference in New Issue