perf: paginate discord-sync + push filters into SQL (#3163)#3190
Conversation
…anshu-byte-coder#3163) The discord notification cron loaded every user with a discord_webhook_url in one unbounded query, then serially walked each through 2-3 GitHub API roundtrips + a supabase update. Both scaled with total user count, so once discord users cross a few hundred the outer loop couldn't finish within the Vercel function timeout and users at the tail were silently skipped. - Adopt the same pagination pattern already used by /api/cron/sync: PAGE_SIZE=50, deterministic .order("id"), .range(page*50, page*50+49), break out when a short page is returned. - Push the "hasn't been notified in the last 20 hours" and "not currently muted" filters into the SQL WHERE clause via .or() so we don't fetch rows we'll immediately skip. Cuts the wire payload per page down to actual candidates. - Cache `twentyHoursAgo` and `nowIso` outside the loop so we don't recompute them per page. Kept the per-user localHour / weekday / streak-at-risk / weekly-summary logic intact — no behavior change for actual notification decisions. Fixes Priyanshu-byte-coder#3163
|
Hi @vedant7007 — thanks for the PR! 🙌 DevTrack asks contributors to ⭐ star the repo before a PR can be merged. It takes two seconds and is the easiest way to support the project. Once you've starred, the |
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
|
starred the repo — should turn the star-required gate green on the next re-run 🌟 |
0914c32
into
Priyanshu-byte-coder:main
|
🎉 Merged! Thanks for contributing to DevTrack. If the project has been useful to you, a ⭐ star on the repo is the easiest way to support it — it helps DevTrack get discovered by more developers. Keep an eye on open issues for your next contribution! |
Summary
`/api/notifications/discord-sync` did one unbounded `.select()` and pulled every user with a discord webhook (webhook URL, timezone, mute state, last notification timestamp) into serverless memory in a single response — then serially walked each through 2-3 GitHub API roundtrips + a Supabase update. Both scaled with total user count, so once discord users cross a few hundred the outer loop can't finish within the Vercel function timeout and users at the tail get silently skipped every hour.
What changed
What's unchanged
The per-user `localHour` / weekday / streak-at-risk / weekly-summary / milestone / notification-sending logic is identical to the old code path. No behavior change for notification decisions — only the fetch/scan strategy differs.
Test plan
Fixes #3163