feat: broadcast
This commit is contained in:
@@ -54,6 +54,30 @@ func (r *PushRepo) ListByUser(ctx context.Context, userID string) ([]model.PushS
|
||||
|
||||
// PruneToMostRecent keeps only the `keep` most-recently-used subscriptions for
|
||||
// a user, deleting older ones — a soft per-user device cap.
|
||||
// SubscribedUserIDs lists everyone with at least one live push subscription.
|
||||
//
|
||||
// Used by broadcasts, which fan out to the whole user base: iterating users
|
||||
// and asking each for subscriptions would query for the (large) majority who
|
||||
// have never enabled push.
|
||||
func (r *PushRepo) SubscribedUserIDs(ctx context.Context) ([]string, error) {
|
||||
rows, err := r.pg.Pool.Query(ctx,
|
||||
`SELECT DISTINCT user_id FROM push_subscriptions`)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("subscribed users: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
out := []string{}
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, fmt.Errorf("scan subscribed user: %w", err)
|
||||
}
|
||||
out = append(out, id)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
func (r *PushRepo) PruneToMostRecent(ctx context.Context, userID string, keep int) error {
|
||||
if keep < 1 {
|
||||
keep = 1
|
||||
|
||||
Reference in New Issue
Block a user