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/notification.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/notification.go')
-rw-r--r-- | internal/db/bundb/notification.go | 35 |
1 files changed, 7 insertions, 28 deletions
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 |