Changeset 96c714f in Klonkt for src/services/PushService.js
- Timestamp:
- 07/22/2026 07:12:11 AM (7 weeks ago)
- Branches:
- main
- Children:
- 9a00f28
- Parents:
- 8240e80
- git-author:
- Robin <roboburr@…> (07/22/2026 07:11:54 AM)
- git-committer:
- Robin <roboburr@…> (07/22/2026 07:12:11 AM)
- File:
-
- 1 edited
-
src/services/PushService.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/PushService.js
r8240e80 r96c714f 118 118 } 119 119 120 // Burst throttle: a wave of likes or a mass-follow must not become a wave of 121 // pushes. Per (user, type) at most one push per window; extras drop silently 122 // (the events themselves are still in Berichten — only the ping is deduped). 123 // In-memory is fine: one process, and a restart just means one extra ping. 124 const THROTTLE_SECONDS = { follow: 60, reply: 30, dm: 30, like: 300, boost: 300, test: 0 }; 125 const _lastPush = new Map(); 126 export function throttled(userId, type, nowSeconds = Math.floor(Date.now() / 1000)) { 127 const windowS = THROTTLE_SECONDS[type] ?? 60; 128 if (!windowS) return false; 129 const key = `${userId}:${type}`; 130 const prev = _lastPush.get(key) || 0; 131 if (nowSeconds - prev < windowS) return true; 132 _lastPush.set(key, nowSeconds); 133 return false; 134 } 135 120 136 // Notify one user on all their devices, honouring per-type preferences. 121 137 // type ∈ {follow, reply, like, boost, dm, test}. Fire-and-forget at call sites. 122 138 export async function notifyUser(userId, { type, title, body, url }) { 123 139 if (!(await pushReady())) return 0; 140 if (throttled(userId, type)) return 0; 124 141 const rows = db.prepare('SELECT * FROM push_subscriptions WHERE user_id = ?').all(userId); 125 142 let sent = 0; … … 143 160 144 161 export default { 145 publicKey, pushReady, DEFAULT_ALERTS, 162 publicKey, pushReady, DEFAULT_ALERTS, throttled, 146 163 saveSubscription, deleteSubscription, listSubscriptions, updateAlerts, 147 164 notifyUser, notifySite,
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)