-
Notifications
You must be signed in to change notification settings - Fork 2.8k
chore: add time logging to the payout processing route #3205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add time logging to the payout processing route #3205
Conversation
|
@lucasfcosta is attempting to deploy a commit to the Dub Team on Vercel. A member of the Team first needs to authorize it. |
|
Caution Review failedThe pull request is closed. WalkthroughAdds timing instrumentation around QStash verification, the Prisma database query, audit log creation, and the Resend batch email API call; restructures email sends into a single batched request and logs consolidated per-step timings. Changes
Sequence Diagram(s)sequenceDiagram
participant Q as QStash
participant Server as RouteHandler
participant DB as Prisma
participant Audit as AuditLog
participant Resend as ResendAPI
Server->>Q: verify request (timing start t0)
Q-->>Server: verification result (record qstashVerification)
Server->>DB: query payouts/recipients (t1)
DB-->>Server: query result (record prismaQuery)
Server->>Audit: create audit log (t2)
Audit-->>Server: audit saved (record auditLog)
Server->>Resend: send batch emails (t3)
Resend-->>Server: response (record resendBatchApi)
Server->>Server: compute totalMs and log consolidated timings
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
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. Comment |
There was a problem hiding this 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
🧹 Nitpick comments (2)
apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts (2)
64-68: Consider logging timings before early returns.This early return bypasses the timing log at lines 133-150, losing
qstashVerificationandprismaQuerytiming data. If you want comprehensive profiling, consider logging partial timings before returning.
152-166: Consider timing the qstash.publishJSON call.For comprehensive bottleneck analysis, you may also want to time this external call to qstash when enqueuing the next batch.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts(4 hunks)
🔇 Additional comments (5)
apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts (5)
24-25: LGTM - Clean timing instrumentation setup.The use of
performance.now()for high-resolution timing is appropriate for this use case.
30-35: LGTM.
41-62: LGTM.
133-150: LGTM - Well-structured timing output.The structured JSON logging with consistent rounding and null handling for optional timings will be easy to parse and analyze.
104-110: The non-null assertions onpartner.emailare intentional and safe.Lines 105 and 110 use
!onpayout.partner.emailas part of the established pattern in this codebase:sendBatchEmailfilters out emails with invalidtoaddresses internally, making null checks at call sites unnecessary. This centralized validation approach is used throughout the payouts system.The
replyTo: payout.program.supportEmail || "noreply"fallback on line 108 may need review if "noreply" should be a fully qualified email address, but that's a separate concern from the non-null assertions.
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this 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
♻️ Duplicate comments (1)
apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts (1)
104-129: Useundefinedinstead of invalid"noreply"reply‑to address
replyTo: payout.program.supportEmail || "noreply"introduces an invalid email address value. Unliketo, which the email layer centrally filters for invalid addresses (per repository learnings),replyTomay be forwarded as‑is to Resend/SMTP and cause validation errors.A safer change is to omit
replyTowhen there is no support email, or use a guaranteed‑valid configured no‑reply address:- replyTo: payout.program.supportEmail || "noreply", + replyTo: payout.program.supportEmail || undefined,(or wire this to a
NO_REPLY_EMAILenv/config value that is a valid email).
🧹 Nitpick comments (1)
apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts (1)
24-150: Timing instrumentation is correct and side‑effect freeThe new timing markers (startTime, t0–t3, timings, and the consolidated timings log) are well placed around the expensive async calls and don’t change route behavior. The numbers you log (per‑step + totalMs) should give a clear picture of where time is spent.
As an optional improvement, you could give
timingsan explicit shape instead ofRecord<string, number>to catch typos at compile time, e.g.:const timings: { qstashVerification: number; prismaQuery: number; auditLog: number; resendBatchApi?: number; } = { qstashVerification: 0, prismaQuery: 0, auditLog: 0 };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts(4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 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/payouts/process/updates/route.ts
🧬 Code graph analysis (1)
apps/web/app/(ee)/api/cron/payouts/process/updates/route.ts (3)
packages/utils/src/functions/currency-formatter.ts (1)
currencyFormatter(7-22)packages/email/src/templates/partner-payout-confirmed.tsx (1)
PartnerPayoutConfirmed(24-160)packages/email/src/index.ts (1)
sendBatchEmail(31-70)
This adds more detailed logging so we can time the execution of the different parts of the
POST /api/cron/payouts/process/updatesroute.This will help us determine which part of it is slow, and track how long the call to the Resend API is taking vs. the other operations and identify possible bottlenecks.
I couldn't find more detailed tracing libraries here so I defaulted to a pattern that seems to be used elsewhere that's simple enough for us to observe in the logs. Please let me know if I got it wrong and apologies in advance if I did.
Summary by CodeRabbit
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.