Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Dec 8, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Campaign email broadcasts now use chunked batch processing with per-chunk tracking and improved error handling, increasing reliability and consistency for large recipient lists.
    • Notification records are created per processed chunk to ensure accurate delivery records.
    • Existing scheduling/delay behavior preserved while improving stability during high-volume broadcasts.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Contributor

vercel bot commented Dec 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Dec 8, 2025 10:37am

@devkiran devkiran requested a review from steven-tey December 8, 2025 10:02
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Warning

Rate limit exceeded

@devkiran has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 18 minutes and 17 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b014847 and f7178dd.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts (2 hunks)

Walkthrough

The broadcast campaign route now splits partnerUsers into EMAIL_BATCH_SIZE chunks, sends each chunk with a unique per-chunk idempotency key, creates NotificationEmail records after each chunk's successful response, and preserves per-chunk error handling and batching delays.

Changes

Cohort / File(s) Summary
Email batch chunking & idempotency
apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts
Splits partnerUsers into chunks (EMAIL_BATCH_SIZE) and iterates per-chunk; generates per-chunk idempotency keys using campaign.id, `startingAfter

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant CronRoute as API Route
    participant ChunkSender as sendBatchEmail / Email Provider
    participant DB as Database (NotificationEmail)
    participant Enqueue as Batch Enqueue / Scheduler

    CronRoute->>CronRoute: split partnerUsers into chunks
    loop for each chunk i
        CronRoute->>ChunkSender: sendChunk(payload, idempotencyKey_i)
        alt success
            ChunkSender-->>CronRoute: success + data
            CronRoute->>DB: create NotificationEmail records for chunk i
            CronRoute->>Enqueue: schedule next overall batch (if applicable)
        else failure
            ChunkSender-->>CronRoute: error
            CronRoute->>CronRoute: log error, continue or halt per logic
        end
        CronRoute->>CronRoute: optional delay between chunks
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Validate idempotency key format and uniqueness across retries
  • Confirm NotificationEmail creation now aligns with downstream read/query expectations
  • Check edge cases: empty partnerUsers, partial chunk failures, and enqueue transition for final batch

Possibly related PRs

Suggested reviewers

  • steven-tey

Poem

🐇 Hop by hop the batches run,

Chunks dispatched until the job is done,
Keys in paw keep repeats away,
Tiny notes recorded chunk-by-chunk today,
— a rabbit's cheer for cleaner play ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing email chunking for campaign broadcasts to handle large partner user lists in batches.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 23ae40e and b5d6cd5.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-17T05:19:11.972Z
Learnt from: devkiran
Repo: dubinc/dub PR: 3113
File: apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-paypal-payouts.ts:65-75
Timestamp: 2025-11-17T05:19:11.972Z
Learning: In the Dub codebase, `sendBatchEmail` (implemented in packages/email/src/send-via-resend.ts) handles filtering of emails with invalid `to` addresses internally. Call sites can safely use non-null assertions on email addresses because the email sending layer will filter out any entries with null/undefined `to` values before sending. This centralized validation pattern is intentional and removes the need for filtering at individual call sites.

Applied to files:

  • apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts
📚 Learning: 2025-11-12T22:23:10.414Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 3098
File: apps/web/lib/actions/partners/message-program.ts:49-58
Timestamp: 2025-11-12T22:23:10.414Z
Learning: In apps/web/lib/actions/partners/message-program.ts, when checking if a partner can continue messaging after messaging is disabled, the code intentionally requires `senderPartnerId: null` (program-initiated messages) to prevent partners from continuing to send junk messages. Only conversations started by the program should continue after messaging is disabled, as a spam prevention mechanism.

Applied to files:

  • apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts (1)

12-12: Import additions align with downstream usage

APP_DOMAIN_WITH_NGROK, chunk, and log are all used below (QStash URL, partner user chunking, and logging), so this import change is consistent and safe.

@steven-tey steven-tey merged commit b54ef3c into main Dec 8, 2025
7 of 8 checks passed
@steven-tey steven-tey deleted the campaign-broadcast-fix branch December 8, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants