fix: push notification
This commit is contained in:
@@ -52,6 +52,28 @@ func (r *PushRepo) ListByUser(ctx context.Context, userID string) ([]model.PushS
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
// PruneToMostRecent keeps only the `keep` most-recently-used subscriptions for
|
||||
// a user, deleting older ones — a soft per-user device cap.
|
||||
func (r *PushRepo) PruneToMostRecent(ctx context.Context, userID string, keep int) error {
|
||||
if keep < 1 {
|
||||
keep = 1
|
||||
}
|
||||
_, err := r.pg.Pool.Exec(ctx, `
|
||||
DELETE FROM push_subscriptions
|
||||
WHERE user_id = $1 AND id NOT IN (
|
||||
SELECT id FROM push_subscriptions
|
||||
WHERE user_id = $1
|
||||
ORDER BY last_used_at DESC NULLS LAST
|
||||
LIMIT $2
|
||||
)`,
|
||||
userID, keep,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("prune push subscriptions: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteByEndpoint removes a subscription (on unsubscribe or when the push
|
||||
// service reports it gone).
|
||||
func (r *PushRepo) DeleteByEndpoint(ctx context.Context, endpoint string) error {
|
||||
|
||||
Reference in New Issue
Block a user