MCPcopy Index your code
hub / github.com/coder/coder / subscriptionsForUser

Method subscriptionsForUser

coderd/webpush/webpush.go:289–312  ·  view source on GitHub ↗
(ctx context.Context, userID uuid.UUID)

Source from the content-addressed store, hash-verified

287}
288
289func (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
314func (n *Webpusher) cachedSubscriptions(userID uuid.UUID) ([]database.WebpushSubscription, bool) {
315 n.cacheMu.RLock()

Callers 1

DispatchMethod · 0.95

Calls 7

cachedSubscriptionsMethod · 0.95
storeSubscriptionsMethod · 0.95
DoMethod · 0.65
StringMethod · 0.45
CloneMethod · 0.45

Tested by

no test coverage detected