mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 14:52:26 -05:00
[chore] bump go structr cache version -> v0.6.0 (#2773)
* update go-structr library -> v0.6.0, add necessary wrapping types + code changes to support these changes
* update readme with go-structr package changes
* improved wrapping of the SliceCache type
* add code comments for the cache wrapper types
* remove test.out 😇
---------
Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
This commit is contained in:
parent
f05874be30
commit
adf345f1ec
62 changed files with 2412 additions and 5857 deletions
|
|
@ -76,23 +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.GTS.Emoji.Invalidate("ID", id)
|
||||
|
||||
for _, accountID := range accountIDs {
|
||||
// Invalidate cached account.
|
||||
e.state.Caches.GTS.
|
||||
Account.
|
||||
Invalidate("ID", accountID)
|
||||
}
|
||||
|
||||
for _, statusID := range statusIDs {
|
||||
// Invalidate cached account.
|
||||
e.state.Caches.GTS.
|
||||
Status.
|
||||
Invalidate("ID", statusID)
|
||||
}
|
||||
// Invalidate cached account and status IDs.
|
||||
e.state.Caches.GTS.Account.InvalidateIDs("ID", accountIDs)
|
||||
e.state.Caches.GTS.Status.InvalidateIDs("ID", statusIDs)
|
||||
}()
|
||||
|
||||
// Load emoji into cache before attempting a delete,
|
||||
|
|
@ -594,23 +582,10 @@ func (e *emojiDB) GetEmojisByIDs(ctx context.Context, ids []string) ([]*gtsmodel
|
|||
return nil, db.ErrNoEntries
|
||||
}
|
||||
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all emoji IDs via cache loader callbacks.
|
||||
emojis, err := e.state.Caches.GTS.Emoji.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached emoji loader function.
|
||||
func() ([]*gtsmodel.Emoji, error) {
|
||||
emojis, err := e.state.Caches.GTS.Emoji.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Emoji, error) {
|
||||
// Preallocate expected length of uncached emojis.
|
||||
emojis := make([]*gtsmodel.Emoji, 0, len(uncached))
|
||||
|
||||
|
|
@ -671,23 +646,10 @@ func (e *emojiDB) GetEmojiCategoriesByIDs(ctx context.Context, ids []string) ([]
|
|||
return nil, db.ErrNoEntries
|
||||
}
|
||||
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all category IDs via cache loader callbacks.
|
||||
categories, err := e.state.Caches.GTS.EmojiCategory.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached emoji loader function.
|
||||
func() ([]*gtsmodel.EmojiCategory, error) {
|
||||
categories, err := e.state.Caches.GTS.EmojiCategory.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.EmojiCategory, error) {
|
||||
// Preallocate expected length of uncached categories.
|
||||
categories := make([]*gtsmodel.EmojiCategory, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
|
|
@ -79,17 +79,9 @@ func (f *filterDB) GetFiltersForAccountID(ctx context.Context, accountID string)
|
|||
}
|
||||
|
||||
// Get each filter by ID from the cache or DB.
|
||||
uncachedFilterIDs := make([]string, 0, len(filterIDs))
|
||||
filters, err := f.state.Caches.GTS.Filter.Load(
|
||||
"ID",
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range filterIDs {
|
||||
if !load(id) {
|
||||
uncachedFilterIDs = append(uncachedFilterIDs, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
func() ([]*gtsmodel.Filter, error) {
|
||||
filters, err := f.state.Caches.GTS.Filter.LoadIDs("ID",
|
||||
filterIDs,
|
||||
func(uncachedFilterIDs []string) ([]*gtsmodel.Filter, error) {
|
||||
uncachedFilters := make([]*gtsmodel.Filter, 0, len(uncachedFilterIDs))
|
||||
if err := f.db.
|
||||
NewSelect().
|
||||
|
|
|
|||
|
|
@ -97,17 +97,9 @@ func (f *filterDB) getFilterKeywords(ctx context.Context, idColumn string, id st
|
|||
}
|
||||
|
||||
// Get each filter keyword by ID from the cache or DB.
|
||||
uncachedFilterKeywordIDs := make([]string, 0, len(filterKeywordIDs))
|
||||
filterKeywords, err := f.state.Caches.GTS.FilterKeyword.Load(
|
||||
"ID",
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range filterKeywordIDs {
|
||||
if !load(id) {
|
||||
uncachedFilterKeywordIDs = append(uncachedFilterKeywordIDs, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
func() ([]*gtsmodel.FilterKeyword, error) {
|
||||
filterKeywords, err := f.state.Caches.GTS.FilterKeyword.LoadIDs("ID",
|
||||
filterKeywordIDs,
|
||||
func(uncachedFilterKeywordIDs []string) ([]*gtsmodel.FilterKeyword, error) {
|
||||
uncachedFilterKeywords := make([]*gtsmodel.FilterKeyword, 0, len(uncachedFilterKeywordIDs))
|
||||
if err := f.db.
|
||||
NewSelect().
|
||||
|
|
|
|||
|
|
@ -97,17 +97,9 @@ func (f *filterDB) getFilterStatuses(ctx context.Context, idColumn string, id st
|
|||
}
|
||||
|
||||
// Get each filter status by ID from the cache or DB.
|
||||
uncachedFilterStatusIDs := make([]string, 0, len(filterStatusIDs))
|
||||
filterStatuses, err := f.state.Caches.GTS.FilterStatus.Load(
|
||||
"ID",
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range filterStatusIDs {
|
||||
if !load(id) {
|
||||
uncachedFilterStatusIDs = append(uncachedFilterStatusIDs, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
func() ([]*gtsmodel.FilterStatus, error) {
|
||||
filterStatuses, err := f.state.Caches.GTS.FilterStatus.LoadIDs("ID",
|
||||
filterStatusIDs,
|
||||
func(uncachedFilterStatusIDs []string) ([]*gtsmodel.FilterStatus, error) {
|
||||
uncachedFilterStatuses := make([]*gtsmodel.FilterStatus, 0, len(uncachedFilterStatusIDs))
|
||||
if err := f.db.
|
||||
NewSelect().
|
||||
|
|
|
|||
|
|
@ -341,23 +341,10 @@ func (l *listDB) GetListEntries(ctx context.Context,
|
|||
}
|
||||
|
||||
func (l *listDB) GetListsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.List, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all list IDs via cache loader callbacks.
|
||||
lists, err := l.state.Caches.GTS.List.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached list loader function.
|
||||
func() ([]*gtsmodel.List, error) {
|
||||
lists, err := l.state.Caches.GTS.List.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.List, error) {
|
||||
// Preallocate expected length of uncached lists.
|
||||
lists := make([]*gtsmodel.List, 0, len(uncached))
|
||||
|
||||
|
|
@ -401,23 +388,10 @@ func (l *listDB) GetListsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.L
|
|||
}
|
||||
|
||||
func (l *listDB) GetListEntriesByIDs(ctx context.Context, ids []string) ([]*gtsmodel.ListEntry, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all entry IDs via cache loader callbacks.
|
||||
entries, err := l.state.Caches.GTS.ListEntry.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached entry loader function.
|
||||
func() ([]*gtsmodel.ListEntry, error) {
|
||||
entries, err := l.state.Caches.GTS.ListEntry.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.ListEntry, error) {
|
||||
// Preallocate expected length of uncached entries.
|
||||
entries := make([]*gtsmodel.ListEntry, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
|
|
@ -53,23 +53,10 @@ func (m *mediaDB) GetAttachmentByID(ctx context.Context, id string) (*gtsmodel.M
|
|||
}
|
||||
|
||||
func (m *mediaDB) GetAttachmentsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.MediaAttachment, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all media IDs via cache loader callbacks.
|
||||
media, err := m.state.Caches.GTS.Media.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached media loader function.
|
||||
func() ([]*gtsmodel.MediaAttachment, error) {
|
||||
media, err := m.state.Caches.GTS.Media.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.MediaAttachment, error) {
|
||||
// Preallocate expected length of uncached media attachments.
|
||||
media := make([]*gtsmodel.MediaAttachment, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
|
|
@ -65,23 +65,10 @@ func (m *mentionDB) GetMention(ctx context.Context, id string) (*gtsmodel.Mentio
|
|||
}
|
||||
|
||||
func (m *mentionDB) GetMentions(ctx context.Context, ids []string) ([]*gtsmodel.Mention, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all mention IDs via cache loader callbacks.
|
||||
mentions, err := m.state.Caches.GTS.Mention.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached mention loader function.
|
||||
func() ([]*gtsmodel.Mention, error) {
|
||||
mentions, err := m.state.Caches.GTS.Mention.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Mention, error) {
|
||||
// Preallocate expected length of uncached mentions.
|
||||
mentions := make([]*gtsmodel.Mention, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
|
|
@ -104,23 +104,10 @@ func (n *notificationDB) getNotification(ctx context.Context, lookup string, dbQ
|
|||
}
|
||||
|
||||
func (n *notificationDB) GetNotificationsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Notification, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all notif IDs via cache loader callbacks.
|
||||
notifs, err := n.state.Caches.GTS.Notification.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached notification loader function.
|
||||
func() ([]*gtsmodel.Notification, error) {
|
||||
notifs, err := n.state.Caches.GTS.Notification.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Notification, error) {
|
||||
// Preallocate expected length of uncached notifications.
|
||||
notifs := make([]*gtsmodel.Notification, 0, len(uncached))
|
||||
|
||||
|
|
@ -345,12 +332,8 @@ func (n *notificationDB) DeleteNotifications(ctx context.Context, types []string
|
|||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// Invalidate all IDs on return.
|
||||
for _, id := range notifIDs {
|
||||
n.state.Caches.GTS.Notification.Invalidate("ID", id)
|
||||
}
|
||||
}()
|
||||
// Invalidate all cached notifications by IDs on return.
|
||||
defer n.state.Caches.GTS.Notification.InvalidateIDs("ID", notifIDs)
|
||||
|
||||
// Load all notif into cache, this *really* isn't great
|
||||
// but it is the only way we can ensure we invalidate all
|
||||
|
|
@ -383,12 +366,8 @@ func (n *notificationDB) DeleteNotificationsForStatus(ctx context.Context, statu
|
|||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// Invalidate all IDs on return.
|
||||
for _, id := range notifIDs {
|
||||
n.state.Caches.GTS.Notification.Invalidate("ID", id)
|
||||
}
|
||||
}()
|
||||
// Invalidate all cached notifications by IDs on return.
|
||||
defer n.state.Caches.GTS.Notification.InvalidateIDs("ID", notifIDs)
|
||||
|
||||
// Load all notif into cache, this *really* isn't great
|
||||
// but it is the only way we can ensure we invalidate all
|
||||
|
|
|
|||
|
|
@ -270,23 +270,10 @@ func (p *pollDB) GetPollVotes(ctx context.Context, pollID string) ([]*gtsmodel.P
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(voteIDs))
|
||||
|
||||
// Load all votes from IDs via cache loader callbacks.
|
||||
votes, err := p.state.Caches.GTS.PollVote.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range voteIDs {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached poll vote loader function.
|
||||
func() ([]*gtsmodel.PollVote, error) {
|
||||
votes, err := p.state.Caches.GTS.PollVote.LoadIDs("ID",
|
||||
voteIDs,
|
||||
func(uncached []string) ([]*gtsmodel.PollVote, error) {
|
||||
// Preallocate expected length of uncached votes.
|
||||
votes := make([]*gtsmodel.PollVote, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ func (r *relationshipDB) CountAccountBlocks(ctx context.Context, accountID strin
|
|||
}
|
||||
|
||||
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.GTS.FollowIDs, ">"+accountID, page, func() ([]string, error) {
|
||||
var followIDs []string
|
||||
|
||||
// Follow IDs not in cache, perform DB query!
|
||||
|
|
@ -233,7 +233,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.GTS.FollowIDs, "<"+accountID, page, func() ([]string, error) {
|
||||
var followIDs []string
|
||||
|
||||
// Follow IDs not in cache, perform DB query!
|
||||
|
|
@ -263,7 +263,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.GTS.FollowRequestIDs, ">"+accountID, page, func() ([]string, error) {
|
||||
var followReqIDs []string
|
||||
|
||||
// Follow request IDs not in cache, perform DB query!
|
||||
|
|
@ -278,7 +278,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.GTS.FollowRequestIDs, "<"+accountID, page, func() ([]string, error) {
|
||||
var followReqIDs []string
|
||||
|
||||
// Follow request IDs not in cache, perform DB query!
|
||||
|
|
@ -293,7 +293,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.GTS.BlockIDs, accountID, page, func() ([]string, error) {
|
||||
var blockIDs []string
|
||||
|
||||
// Block IDs not in cache, perform DB query!
|
||||
|
|
|
|||
|
|
@ -101,23 +101,10 @@ func (r *relationshipDB) GetBlock(ctx context.Context, sourceAccountID string, t
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetBlocksByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Block, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all blocks IDs via cache loader callbacks.
|
||||
blocks, err := r.state.Caches.GTS.Block.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached block loader function.
|
||||
func() ([]*gtsmodel.Block, error) {
|
||||
blocks, err := r.state.Caches.GTS.Block.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Block, error) {
|
||||
// Preallocate expected length of uncached blocks.
|
||||
blocks := make([]*gtsmodel.Block, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
|
|
@ -78,23 +78,10 @@ func (r *relationshipDB) GetFollow(ctx context.Context, sourceAccountID string,
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetFollowsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Follow, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all follow IDs via cache loader callbacks.
|
||||
follows, err := r.state.Caches.GTS.Follow.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached follow loader function.
|
||||
func() ([]*gtsmodel.Follow, error) {
|
||||
follows, err := r.state.Caches.GTS.Follow.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Follow, error) {
|
||||
// Preallocate expected length of uncached follows.
|
||||
follows := make([]*gtsmodel.Follow, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
|
|
@ -77,23 +77,10 @@ func (r *relationshipDB) GetFollowRequest(ctx context.Context, sourceAccountID s
|
|||
}
|
||||
|
||||
func (r *relationshipDB) GetFollowRequestsByIDs(ctx context.Context, ids []string) ([]*gtsmodel.FollowRequest, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all follow IDs via cache loader callbacks.
|
||||
follows, err := r.state.Caches.GTS.FollowRequest.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached follow req loader function.
|
||||
func() ([]*gtsmodel.FollowRequest, error) {
|
||||
follows, err := r.state.Caches.GTS.FollowRequest.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.FollowRequest, error) {
|
||||
// Preallocate expected length of uncached followReqs.
|
||||
follows := make([]*gtsmodel.FollowRequest, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
|
|
@ -50,23 +50,10 @@ func (s *statusDB) GetStatusByID(ctx context.Context, id string) (*gtsmodel.Stat
|
|||
}
|
||||
|
||||
func (s *statusDB) GetStatusesByIDs(ctx context.Context, ids []string) ([]*gtsmodel.Status, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all status IDs via cache loader callbacks.
|
||||
statuses, err := s.state.Caches.GTS.Status.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached statuses loader function.
|
||||
func() ([]*gtsmodel.Status, error) {
|
||||
// Load all input status IDs via cache loader callback.
|
||||
statuses, err := s.state.Caches.GTS.Status.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Status, error) {
|
||||
// Preallocate expected length of uncached statuses.
|
||||
statuses := make([]*gtsmodel.Status, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
|
|
@ -113,23 +113,10 @@ func (s *statusFaveDB) GetStatusFaves(ctx context.Context, statusID string) ([]*
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(faveIDs))
|
||||
|
||||
// Load all fave IDs via cache loader callbacks.
|
||||
faves, err := s.state.Caches.GTS.StatusFave.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range faveIDs {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached status faves loader function.
|
||||
func() ([]*gtsmodel.StatusFave, error) {
|
||||
faves, err := s.state.Caches.GTS.StatusFave.LoadIDs("ID",
|
||||
faveIDs,
|
||||
func(uncached []string) ([]*gtsmodel.StatusFave, error) {
|
||||
// Preallocate expected length of uncached faves.
|
||||
faves := make([]*gtsmodel.StatusFave, 0, len(uncached))
|
||||
|
||||
|
|
@ -318,13 +305,11 @@ func (s *statusFaveDB) DeleteStatusFaves(ctx context.Context, targetAccountID st
|
|||
// Deduplicate determined status IDs.
|
||||
statusIDs = util.Deduplicate(statusIDs)
|
||||
|
||||
for _, id := range statusIDs {
|
||||
// Invalidate any cached status faves for this status.
|
||||
s.state.Caches.GTS.StatusFave.Invalidate("ID", id)
|
||||
// Invalidate any cached status faves for this status ID.
|
||||
s.state.Caches.GTS.StatusFave.InvalidateIDs("ID", statusIDs)
|
||||
|
||||
// Invalidate any cached status fave IDs for this status.
|
||||
s.state.Caches.GTS.StatusFaveIDs.Invalidate(id)
|
||||
}
|
||||
// Invalidate any cached status fave IDs for this status ID.
|
||||
s.state.Caches.GTS.StatusFaveIDs.Invalidate(statusIDs...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,23 +71,10 @@ func (t *tagDB) GetTagByName(ctx context.Context, name string) (*gtsmodel.Tag, e
|
|||
}
|
||||
|
||||
func (t *tagDB) GetTags(ctx context.Context, ids []string) ([]*gtsmodel.Tag, error) {
|
||||
// Preallocate at-worst possible length.
|
||||
uncached := make([]string, 0, len(ids))
|
||||
|
||||
// Load all tag IDs via cache loader callbacks.
|
||||
tags, err := t.state.Caches.GTS.Tag.Load("ID",
|
||||
|
||||
// Load cached + check for uncached.
|
||||
func(load func(keyParts ...any) bool) {
|
||||
for _, id := range ids {
|
||||
if !load(id) {
|
||||
uncached = append(uncached, id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Uncached tag loader function.
|
||||
func() ([]*gtsmodel.Tag, error) {
|
||||
tags, err := t.state.Caches.GTS.Tag.LoadIDs("ID",
|
||||
ids,
|
||||
func(uncached []string) ([]*gtsmodel.Tag, error) {
|
||||
// Preallocate expected length of uncached tags.
|
||||
tags := make([]*gtsmodel.Tag, 0, len(uncached))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue