Skip to content

fix: paginate weekly-digest cron query to prevent serverless timeout - #2363

Closed
Meera2906 wants to merge 2 commits into
Priyanshu-byte-coder:mainfrom
Meera2906:fix/weekly-digest-cron-timeout
Closed

fix: paginate weekly-digest cron query to prevent serverless timeout#2363
Meera2906 wants to merge 2 commits into
Priyanshu-byte-coder:mainfrom
Meera2906:fix/weekly-digest-cron-timeout

Conversation

@Meera2906

Copy link
Copy Markdown
Contributor

Problem

The weekly-digest cron fetched all opted-in users in a single unbounded
Supabase query. With 200+ users and ~300ms per email send, the function
reliably exceeded Vercel's 60s timeout, causing partial delivery with no
retry mechanism.

Fix

Replaced the unbounded query with a paginated loop using .range():

  • PAGE_SIZE = 50 rows fetched per Supabase query
  • Existing BATCH_SIZE = 5 parallel email sends is preserved per page
  • Each iteration stays well within the serverless timeout window
  • totalFetched added to logs for observability

Fixes #1852

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix labels Jun 12, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@github-actions github-actions Bot added type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) labels Jun 12, 2026
@Priyanshu-byte-coder Priyanshu-byte-coder added the gssoc:approved GSSoC: PR approved for scoring label Jun 16, 2026
@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

This PR has merge conflicts with the current main branch. Please rebase or merge main into your branch to resolve the conflicts, then push the updated branch. Once conflicts are resolved, this PR will be merged.

git fetch origin main
git merge origin/main
# resolve conflicts
git push

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

CI is failing on the type check. Please fix the TypeScript errors and push again.

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

Pagination logic has a bug: results is referenced outside the Promise.allSettled() call that defines it — the refactoring appears incomplete. The forEach over results is inside the pagination loop but results is never assigned. Please fix the scoping and rebase on main.

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

This has merge conflicts with main. Please rebase/resolve conflicts and make sure CI is green — then it'll get a fresh review.

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

The pagination idea is right (same fix I recently merged for the discord and wakatime cron jobs — #3190/#3203), but this branch doesn't compile: src/app/api/cron/weekly-digest/route.ts has syntax errors —

route.ts(334,13): error TS1128: Declaration or statement expected.
route.ts(349,7): error TS1005: ',' expected.

Fix the syntax so pnpm type-check passes, rebase on main (the weekly-digest route moved), and I'll review the pagination. Mirror the keyset/offset pattern from the discord-sync fix.

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

Closing as stale. The last commit on this branch was 2026-06-17, over a month ago, and there's been no activity since. It also has merge conflicts against current main.

This isn't a rejection of the idea — DevTrack's PR queue grew past 110 open PRs, so I'm clearing branches that have gone quiet so the review tab reflects what's actually in progress.

If you still want to land this: rebase on current main, address any review feedback above, and reopen this PR (or open a fresh one) — I'll review it. Thanks for contributing to DevTrack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC: PR approved for scoring gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: weekly-digest cron fetches all opted-in users with no limit, causing serverless timeout when user count is large

2 participants