perf: paginate wakatime/sync users query (#3161)#3203
Open
vedant7007 wants to merge 1 commit into
Open
Conversation
/api/wakatime/sync did one unbounded `.select()` and pulled every user
with a wakatime API key (plus their encrypted keys) into serverless
memory in a single response. At a few thousand users that would either
hit Supabase's ~4.5 MB response cap, blow the function timeout, or get
killed by the memory limit — and the nightly sync would silently fail.
Adopt the same pagination pattern already in use by /api/cron/sync:
PAGE_SIZE=50, deterministic .order("id"), .range(page*50, page*50+49),
break out when a short page is returned. Kept the inner Promise.allSettled
CHUNK_SIZE=5 for API-call parallelism inside each page.
Fixes Priyanshu-byte-coder#3161
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/wakatime/sync` did one unbounded `.select()` and pulled every user with a wakatime API key (plus their encrypted keys) into serverless memory in a single response. At a few thousand users that would either:
and the nightly sync would silently fail.
What changed
Adopted the same pagination pattern already in use by `/api/cron/sync`:
Kept the inner `Promise.allSettled` `CHUNK_SIZE = 5` for parallelism across the Wakatime API within each page — that part was already sensible, just needed to be nested inside the pagination.
What's unchanged
Decrypt-then-fetch-then-upsert logic per user is identical. No behavior change for the actual sync — only the fetch/scan strategy differs.
Test plan
Fixes #3161