summaryrefslogtreecommitdiff
path: root/internal/db/bundb/notification.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/bundb/notification.go')
-rw-r--r--internal/db/bundb/notification.go35
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