diff options
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/bundb/emoji.go | 58 | ||||
-rw-r--r-- | internal/db/bundb/filter.go | 14 | ||||
-rw-r--r-- | internal/db/bundb/filterkeyword.go | 14 | ||||
-rw-r--r-- | internal/db/bundb/filterstatus.go | 14 | ||||
-rw-r--r-- | internal/db/bundb/list.go | 38 | ||||
-rw-r--r-- | internal/db/bundb/media.go | 19 | ||||
-rw-r--r-- | internal/db/bundb/mention.go | 19 | ||||
-rw-r--r-- | internal/db/bundb/notification.go | 35 | ||||
-rw-r--r-- | internal/db/bundb/poll.go | 19 | ||||
-rw-r--r-- | internal/db/bundb/relationship.go | 10 | ||||
-rw-r--r-- | internal/db/bundb/relationship_block.go | 19 | ||||
-rw-r--r-- | internal/db/bundb/relationship_follow.go | 19 | ||||
-rw-r--r-- | internal/db/bundb/relationship_follow_req.go | 19 | ||||
-rw-r--r-- | internal/db/bundb/status.go | 21 | ||||
-rw-r--r-- | internal/db/bundb/statusfave.go | 29 | ||||
-rw-r--r-- | internal/db/bundb/tag.go | 19 |
16 files changed, 69 insertions, 297 deletions
diff --git a/internal/db/bundb/emoji.go b/internal/db/bundb/emoji.go index 69d33eede..2316e7d71 100644 --- a/internal/db/bundb/emoji.go +++ b/internal/db/bundb/emoji.go @@ -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)) diff --git a/internal/db/bundb/filter.go b/internal/db/bundb/filter.go index bcd572f34..d09a5067d 100644 --- a/internal/db/bundb/filter.go +++ b/internal/db/bundb/filter.go @@ -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(). diff --git a/internal/db/bundb/filterkeyword.go b/internal/db/bundb/filterkeyword.go index 703d58d43..5fd824a0b 100644 --- a/internal/db/bundb/filterkeyword.go +++ b/internal/db/bundb/filterkeyword.go @@ -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(). diff --git a/internal/db/bundb/filterstatus.go b/internal/db/bundb/filterstatus.go index 1e98f5958..78985fba1 100644 --- a/internal/db/bundb/filterstatus.go +++ b/internal/db/bundb/filterstatus.go @@ -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(). diff --git a/internal/db/bundb/list.go b/internal/db/bundb/list.go index fb97c8fe7..92936a49f 100644 --- a/internal/db/bundb/list.go +++ b/internal/db/bundb/list.go @@ -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)) diff --git a/internal/db/bundb/media.go b/internal/db/bundb/media.go index 99ef30d22..ed41e7cd9 100644 --- a/internal/db/bundb/media.go +++ b/internal/db/bundb/media.go @@ -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)) diff --git a/internal/db/bundb/mention.go b/internal/db/bundb/mention.go index 156469544..559e9515c 100644 --- a/internal/db/bundb/mention.go +++ b/internal/db/bundb/mention.go @@ -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)) diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go index 3f3d5fbd6..63fb7ed21 100644 --- a/internal/db/bundb/notification.go +++ b/internal/db/bundb/notification.go @@ -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 diff --git a/internal/db/bundb/poll.go b/internal/db/bundb/poll.go index 37a1f26ab..33b621805 100644 --- a/internal/db/bundb/poll.go +++ b/internal/db/bundb/poll.go @@ -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)) diff --git a/internal/db/bundb/relationship.go b/internal/db/bundb/relationship.go index a97aa71ff..30e3850d2 100644 --- a/internal/db/bundb/relationship.go +++ b/internal/db/bundb/relationship.go @@ -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! diff --git a/internal/db/bundb/relationship_block.go b/internal/db/bundb/relationship_block.go index 178de6aa7..d994559ab 100644 --- a/internal/db/bundb/relationship_block.go +++ b/internal/db/bundb/relationship_block.go @@ -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)) diff --git a/internal/db/bundb/relationship_follow.go b/internal/db/bundb/relationship_follow.go index 93ee69bd7..02b861ae0 100644 --- a/internal/db/bundb/relationship_follow.go +++ b/internal/db/bundb/relationship_follow.go @@ -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)) diff --git a/internal/db/bundb/relationship_follow_req.go b/internal/db/bundb/relationship_follow_req.go index 6fd5eefba..0b897f1fa 100644 --- a/internal/db/bundb/relationship_follow_req.go +++ b/internal/db/bundb/relationship_follow_req.go @@ -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)) diff --git a/internal/db/bundb/status.go b/internal/db/bundb/status.go index 6d1788b5d..4bb9812dc 100644 --- a/internal/db/bundb/status.go +++ b/internal/db/bundb/status.go @@ -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)) diff --git a/internal/db/bundb/statusfave.go b/internal/db/bundb/statusfave.go index d04578076..8e9ff501c 100644 --- a/internal/db/bundb/statusfave.go +++ b/internal/db/bundb/statusfave.go @@ -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 } diff --git a/internal/db/bundb/tag.go b/internal/db/bundb/tag.go index e6297d2ab..db1effaf4 100644 --- a/internal/db/bundb/tag.go +++ b/internal/db/bundb/tag.go @@ -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)) |