Skip to content

[Performance] /api/notifications/discord-sync fetches every discord user in a single query — cron truncates #3163

Closed

Description

@vedant7007

Description

similar shape of bug to the wakatime cron, the discord notification cron loads every user with a discord webhook in a single unbounded query.

The Problem

src/app/api/notifications/discord-sync/route.ts:21-24:

const { data: users, error } = await supabaseAdmin
  .from("users")
  .select("id, github_login, discord_webhook_url, timezone, ...")
  .not("discord_webhook_url", "is", null);

no .range(), no .limit(), no ordering. line 36 then serially loops with for (const user of users) and for each one calls fetchPublicStreak and possibly fetchPublicContributions (github API roundtrips) plus a supabase update. so the query size AND the loop time both scale with total discord users.

failure scenario: this cron runs hourly. once discord users cross a few hundred, the outer loop cannot finish inside the vercel function timeout and the whole batch is truncated. users at the end of the query never get notifications. worse, the initial supabase read pulls all rows including muted / already-notified users that get skipped later at lines 60-77 anyway, so most of the payload is wasted.

Proposed Fix

  • page the users query in batches of 50 same as src/app/api/cron/sync/route.ts:38-128
  • push the "which users need a notification this hour" filters into the SQL where clause: filter on last_discord_notification_at < now() - interval '20 hours' and discord_muted_until is null or discord_muted_until < now() so we do not fetch users we will just skip
  • optionally split streak-at-risk vs weekly-summary into separate scheduled runs so the sunday load does not stack

I would like to work on this under GSSoC 26. please assign!

for labels i think gssoc + level2 + type:performance fits here.

Activity

  1. github-actions commented on Jul 19, 2026

    @github-actions

    ✅ Closed as completed!

    If DevTrack has been useful, a ⭐ star on the repo helps the project grow and reach more developers.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions