diff options
| author | 2024-04-02 11:03:40 +0100 | |
|---|---|---|
| committer | 2024-04-02 12:03:40 +0200 | |
| commit | adf345f1ec0cb76a0df94a4505143d891659cba9 (patch) | |
| tree | e0cca289c0a50f30191d4b65a2c336704570e470 /internal/db/bundb/statusfave.go | |
| parent | [feature] Option to hide followers/following (#2788) (diff) | |
| download | gotosocial-adf345f1ec0cb76a0df94a4505143d891659cba9.tar.xz | |
[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 :innocent:
---------
Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
Diffstat (limited to 'internal/db/bundb/statusfave.go')
| -rw-r--r-- | internal/db/bundb/statusfave.go | 29 |
1 files changed, 7 insertions, 22 deletions
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 } |
