(ctx context.Context, userID uuid.UUID)
| 287 | } |
| 288 | |
| 289 | func (n *Webpusher) subscriptionsForUser(ctx context.Context, userID uuid.UUID) ([]database.WebpushSubscription, error) { |
| 290 | if subscriptions, ok := n.cachedSubscriptions(userID); ok { |
| 291 | return subscriptions, nil |
| 292 | } |
| 293 | |
| 294 | subscriptions, err, _ := n.subscriptionFetches.Do(userID.String(), func() ([]database.WebpushSubscription, error) { |
| 295 | if cached, ok := n.cachedSubscriptions(userID); ok { |
| 296 | return cached, nil |
| 297 | } |
| 298 | |
| 299 | generation := n.subscriptionGeneration(userID) |
| 300 | fetched, err := n.store.GetWebpushSubscriptionsByUserID(ctx, userID) |
| 301 | if err != nil { |
| 302 | return nil, err |
| 303 | } |
| 304 | n.storeSubscriptions(userID, generation, fetched) |
| 305 | return slices.Clone(fetched), nil |
| 306 | }) |
| 307 | if err != nil { |
| 308 | return nil, err |
| 309 | } |
| 310 | |
| 311 | return slices.Clone(subscriptions), nil |
| 312 | } |
| 313 | |
| 314 | func (n *Webpusher) cachedSubscriptions(userID uuid.UUID) ([]database.WebpushSubscription, bool) { |
| 315 | n.cacheMu.RLock() |
no test coverage detected