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

Method pruneSubscriptions

coderd/webpush/webpush.go:355–391  ·  view source on GitHub ↗
(userID uuid.UUID, staleIDs []uuid.UUID)

Source from the content-addressed store, hash-verified

353}
354
355func (n *Webpusher) pruneSubscriptions(userID uuid.UUID, staleIDs []uuid.UUID) {
356 if len(staleIDs) == 0 {
357 return
358 }
359
360 stale := make(map[uuid.UUID]struct{}, len(staleIDs))
361 for _, id := range staleIDs {
362 stale[id] = struct{}{}
363 }
364
365 n.cacheMu.Lock()
366 defer n.cacheMu.Unlock()
367
368 entry, ok := n.subscriptionCache[userID]
369 if !ok {
370 return
371 }
372 if !n.clock.Now().Before(entry.expiresAt) {
373 delete(n.subscriptionCache, userID)
374 return
375 }
376
377 filtered := make([]database.WebpushSubscription, 0, len(entry.subscriptions))
378 for _, subscription := range entry.subscriptions {
379 if _, shouldDelete := stale[subscription.ID]; shouldDelete {
380 continue
381 }
382 filtered = append(filtered, subscription)
383 }
384 if len(filtered) == 0 {
385 delete(n.subscriptionCache, userID)
386 return
387 }
388
389 entry.subscriptions = filtered
390 n.subscriptionCache[userID] = entry
391}
392
393// InvalidateUser clears the cached subscriptions for a user and advances
394// its invalidation generation. Local subscribe and unsubscribe handlers call

Callers 1

Calls 2

LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected