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

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Nov 13, 2025

Summary by CodeRabbit

  • Chores
    • Reworked notification data retrieval to fetch program and partner directly, improving reliability of unread message detection and recipient selection.
    • Updated notification content: email subjects now include program name and unread counts; message previews and payloads are built from recent unread messages and sender info for clearer emails and in-app notifications.

@vercel
Copy link
Contributor

vercel bot commented Nov 13, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Nov 13, 2025 1:12am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 13, 2025

Warning

Rate limit exceeded

@steven-tey has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 13 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 2abce74 and 4dfeb98.

πŸ“’ Files selected for processing (2)
  • apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts (2 hunks)
  • apps/web/app/(ee)/api/cron/messages/notify-program/route.ts (2 hunks)

Walkthrough

Refactors two cron notification routes to fetch partner and program directly (parallel where applicable), rewire unread-message queries to partner/program scopes, rebuild email/react payloads from the new shapes, and adjust notification record creation and recipient derivation accordingly.

Changes

Cohort / File(s) Summary
Notify β€” partner route
apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts
Replace programEnrollment lookup with parallel partner and program fetches. Load partner.messages filtered for last 3 days, unread and senderPartnerId null; include senderUser. Derive recipients from partner.users (with notificationPreferences filter). Rebuild email subject and React payload from program and partner data; update NotificationEmail creation to use partnerId/programId.
Notify β€” program route
apps/web/app/(ee)/api/cron/messages/notify-program/route.ts
Replace programEnrollment-based access with parallel program and partner fetches. Load program.messages filtered for last 3 days and unread (include senderPartner). Derive recipients from program.workspace.users. Reverse message order for previews, compose dynamic subject using program.name, and update NotificationEmail creation to use new programId/partnerId sources.

Sequence Diagram(s)

sequenceDiagram
    participant Cron
    participant DB as Database
    participant Email as Email Service
    participant Log as Notification Log

    rect rgb(220,220,255)
    Note over Cron,DB: OLD flow (via programEnrollment)
    Cron->>DB: findUniqueOrThrow(programEnrollment)
    DB-->>Cron: programEnrollment { partner, program, workspace }
    end

    rect rgb(220,255,220)
    Note over Cron,DB: NEW flow (direct parallel fetches)
    Cron->>DB: Promise.all([findUnique(partnerId), findUnique(programId)])
    DB-->>Cron: partner { messages, users }, program { messages, workspace, name }
    end

    rect rgb(255,245,220)
    Note over Cron: Message filtering & payload build
    Cron->>Cron: Filter messages (last 3 days, unread, sender checks)
    Cron->>Cron: Build React payload & subject (uses program/partner)
    end

    Cron->>Email: sendEmail(recipient, subject, reactPayload)
    Cron->>Log: createMany(NotificationEmail records per recipient)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay attention to Prisma include shapes and that all new access paths (e.g., partner.messages, program.messages, partner.users, program.workspace.users) match the updated queries.
  • Verify message filters (3-day window, unread/email/unread flags), ordering/reversal, and senderUser/senderPartner fallbacks.
  • Confirm NotificationEmail record fields (recipientUserId, programId, partnerId) are populated correctly.

Possibly related PRs

Suggested reviewers

  • TWilson023

Poem

πŸ‡ I hopped from enrollments to partner land,

Fetching messages with a nimble hand.
Programs and partners, fetched side by side,
Emails stitched with data as our guide,
A rabbit cheers for the cleaner stride. ✨

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 clearly and specifically describes the main change: removing programEnrollment dependency from the notify-partner and notify-program API routes, which matches the core refactoring in both modified files.
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.

@steven-tey
Copy link
Collaborator Author

#coderabbitai full review

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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts (1)

120-128: Critical: Add null check before accessing senderUser properties.

The code accesses message.senderUser.name without first checking if senderUser exists. If the user was deleted or is missing, this will throw a TypeError.

Apply this diff to add optional chaining:

-            user: message.senderUser.name
+            user: message.senderUser?.name
               ? {
                   name: message.senderUser.name,
                   image: message.senderUser.image,
                 }
               : {
                   name: program.name,
                   image: program.logo,
                 },
πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 2abce74 and a46d56a.

πŸ“’ Files selected for processing (2)
  • apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts (3 hunks)
  • apps/web/app/(ee)/api/cron/messages/notify-program/route.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
πŸ“š Learning: 2025-11-12T22:23:10.390Z
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.390Z
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/messages/notify-partner/route.ts
  • apps/web/app/(ee)/api/cron/messages/notify-program/route.ts
πŸ“š Learning: 2025-09-17T17:44:03.965Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2857
File: apps/web/lib/actions/partners/update-program.ts:96-0
Timestamp: 2025-09-17T17:44:03.965Z
Learning: In apps/web/lib/actions/partners/update-program.ts, the team prefers to keep the messagingEnabledAt update logic simple by allowing client-provided timestamps rather than implementing server-controlled timestamp logic to avoid added complexity.

Applied to files:

  • apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts
  • apps/web/app/(ee)/api/cron/messages/notify-program/route.ts
🧬 Code graph analysis (2)
apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts (1)
packages/prisma/index.ts (1)
  • prisma (3-9)
apps/web/app/(ee)/api/cron/messages/notify-program/route.ts (1)
packages/prisma/index.ts (1)
  • prisma (3-9)
⏰ 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/messages/notify-partner/route.ts (1)

80-80: LGTM!

The data extraction from the partner object is straightforward and correct. The unreadMessages and partnerUsersToNotify are properly derived from the refactored query structure.

Also applies to: 93-95

@steven-tey
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 13, 2025

βœ… Actions performed

Full review triggered.

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: 0

🧹 Nitpick comments (1)
apps/web/app/(ee)/api/cron/messages/notify-program/route.ts (1)

58-58: Consider removing unused senderPartner include.

The senderPartner relation is included but never used in the email template composition (lines 121-122 only use text and createdAt). Removing this include would reduce unnecessary data fetching.

Apply this diff to remove the unused include:

           include: {
-            senderPartner: true,
           },
πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between a46d56a and 4dfeb98.

πŸ“’ Files selected for processing (2)
  • apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts (2 hunks)
  • apps/web/app/(ee)/api/cron/messages/notify-program/route.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(ee)/api/cron/messages/notify-partner/route.ts
🧰 Additional context used
🧠 Learnings (2)
πŸ“š Learning: 2025-09-17T17:44:03.965Z
Learnt from: TWilson023
Repo: dubinc/dub PR: 2857
File: apps/web/lib/actions/partners/update-program.ts:96-0
Timestamp: 2025-09-17T17:44:03.965Z
Learning: In apps/web/lib/actions/partners/update-program.ts, the team prefers to keep the messagingEnabledAt update logic simple by allowing client-provided timestamps rather than implementing server-controlled timestamp logic to avoid added complexity.

Applied to files:

  • apps/web/app/(ee)/api/cron/messages/notify-program/route.ts
πŸ“š Learning: 2025-11-12T22:23:10.390Z
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.390Z
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/messages/notify-program/route.ts
🧬 Code graph analysis (1)
apps/web/app/(ee)/api/cron/messages/notify-program/route.ts (1)
packages/prisma/index.ts (1)
  • prisma (3-9)
⏰ 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 (3)
apps/web/app/(ee)/api/cron/messages/notify-program/route.ts (3)

36-82: LGTM! Clean refactoring with parallel data fetching.

The refactoring successfully removes the programEnrollment dependency by fetching program and partner directly in parallel. The approach is more efficient and the data access patterns are clear. Using findUniqueOrThrow provides appropriate error handling that will be caught by the outer try-catch block.


93-96: LGTM! Effective duplicate prevention.

The check ensures that only the most recent unread message triggers a notification, preventing duplicate emails if newer messages arrive between scheduling and execution.


109-125: LGTM! Well-implemented email composition.

The dynamic subject line provides clear context about message count, and the message reversal ensures chronological display in the email (oldest to newest). The comment about .toReversed() is helpful for future maintainers.

@steven-tey steven-tey merged commit 805d48e into main Nov 13, 2025
7 of 8 checks passed
@steven-tey steven-tey deleted the update-notify-messages branch November 13, 2025 01:20
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.

2 participants