Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

improve indexes

Steven Tey7718017e8a9a
diff --git a/apps/web/app/(ee)/api/cron/payouts/reconcile-amounts/route.ts b/apps/web/app/(ee)/api/cron/payouts/reconcile-amounts/route.ts
index ce60bf989f..858e2749fb 100644
--- a/apps/web/app/(ee)/api/cron/payouts/reconcile-amounts/route.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/reconcile-amounts/route.ts
@@ -14,8 +14,8 @@ const LOOKBACK_MINUTES = 2;
const LOCK_TTL_SECONDS = 60;
// Finds recently updated pending payouts whose amount does not match
-// SUM(commission.earnings) and reconciles them (update amount or delete empty payouts).
-// Runs every minute.
+// SUM(commission.earnings) and reconciles them (update amount or delete empty payouts)
+// Runs every minute (cron expression: * * * * *)
// GET /api/cron/payouts/reconcile-amounts
export const GET = withCron(async () => {
const response = await withRedisLock({
@@ -24,10 +24,10 @@ export const GET = withCron(async () => {
fn: async () => {
const payouts = await prisma.payout.findMany({
where: {
- status: PayoutStatus.pending,
updatedAt: {
gte: subMinutes(new Date(), LOOKBACK_MINUTES),
},
+ status: PayoutStatus.pending,
},
select: {
id: true,
diff --git a/apps/web/prisma/schema/payout.prisma b/apps/web/prisma/schema/payout.prisma
index 051695b960..d62dd3e909 100644
--- a/apps/web/prisma/schema/payout.prisma
+++ b/apps/web/prisma/schema/payout.prisma
@@ -52,7 +52,7 @@ model Payout {
@@index(partnerId)
@@index(invoiceId)
@@index(status)
- @@index([status, updatedAt])
+ @@index([updatedAt, status]) // used for reconcile-amounts cron job
@@index(method)
@@index(userId)
@@index(stripePayoutId)