-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Improve support for custom commissions in payouts cron #2863
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdjusted the pending commissions filter in the payouts cron to always include custom commissions during holding periods by using an OR condition. When holdingPeriodDays > 0, the query includes type="custom" OR createdAt before threshold; otherwise, no date filter is applied. Updated inline comments accordingly. No changes to clawbacks, payout creation, or aggregation logic. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Cron as Cron (payouts)
participant Service as CreatePayout Handler
participant DB as DB (commissions)
participant Aggregator as Aggregation/Creation
Cron->>Service: Trigger create-payout
alt holdingPeriodDays > 0
Service->>DB: Query pending commissions<br/>WHERE status = pending AND (type = "custom" OR createdAt < threshold)
note right of DB #DDEFEF: Custom commissions always included during holding period
else No holding period
Service->>DB: Query pending commissions<br/>WHERE status = pending (no date filter)
end
Service->>Aggregator: Aggregate eligible commissions
Aggregator-->>Service: Payout data
Service-->>Cron: Create payout result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
⏰ 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)
🔇 Additional comments (2)
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 |
|
@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
🧹 Nitpick comments (2)
apps/web/app/(ee)/api/cron/payouts/create-payout.ts (2)
81-85: Use date-fns subDays and make boundary inclusive.Clearer and less error‑prone than manual ms math; inclusive lte avoids millisecond edge misses.
- createdAt: { - lt: new Date( - Date.now() - holdingPeriodDays * 24 * 60 * 60 * 1000, - ), - }, + createdAt: { + lte: subDays(new Date(), holdingPeriodDays), + },And update imports:
-import { endOfMonth } from "date-fns"; +import { endOfMonth, subDays } from "date-fns";
76-87: Heads‑up: OR may reduce index selectivity; consider split query if this path gets hot.Two targeted queries can leverage indexes better:
- Q1: non‑custom, createdAt <= threshold
- Q2: custom (no date filter)
Then merge and sort in memory (sets are disjoint if Q1 excludes custom).Only worth it if this query shows up in profiles.
Would you like a follow‑up patch or schema index suggestions (e.g., composite index on (programId, partnerId, status, payoutId, earnings, createdAt) plus partial index for type='custom')?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/app/(ee)/api/cron/payouts/create-payout.ts(1 hunks)
⏰ 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 (2)
apps/web/app/(ee)/api/cron/payouts/create-payout.ts (2)
74-89: Custom commissions bypass holding period — change looks correct.The OR condition correctly includes type="custom" regardless of createdAt when holdingPeriodDays > 0. Matches the PR objective without impacting clawbacks logic.
78-79: Verify Prisma field type and prefer enum symbolapps/web/app/(ee)/api/cron/payouts/create-payout.ts (line 78) uses type: "custom" while other places use CommissionType.custom. The verification run did not locate a Commission model or CommissionType enum in packages/prisma/schema/schema.prisma — confirm whether Commission.type is an enum; if so, use CommissionType.custom (or ensure the literal exactly matches the Prisma enum value).
Summary by CodeRabbit