perf: paginate discord-sync + push filters into SQL (#3163)#3190
Open
vedant7007 wants to merge 1 commit into
Open
perf: paginate discord-sync + push filters into SQL (#3163)#3190vedant7007 wants to merge 1 commit into
vedant7007 wants to merge 1 commit into
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):
|
Author
|
starred the repo — should turn the star-required gate green on the next re-run 🌟 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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