Skip to content

Commit

Permalink
Fix no index used
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Jan 9, 2025
1 parent 55523ab commit ccbde0d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
18 changes: 6 additions & 12 deletions api/resolvers/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,21 +467,19 @@ const resolvers = {
// make sure each invoice is only returned once via visibility timeouts and SKIP LOCKED
// we use queryRawUnsafe because Prisma does not support tsrange
// see https://www.prisma.io/docs/orm/overview/databases/postgresql
return await models.$queryRawUnsafe(`
return await models.$queryRaw`
WITH failed AS (
UPDATE "Invoice"
SET "lockedAt" = now()
WHERE id IN (
SELECT id FROM "Invoice"
WHERE "userId" = $1
WHERE "userId" = ${me.id}
AND "actionState" = 'FAILED'
AND "userCancel" = false
AND now()::timestamp <@ tsrange(
"cancelledAt" + $2::interval,
"cancelledAt" + $3::interval
)
AND "cancelledAt" < now() - ${`${WALLET_RETRY_AFTER_MS} milliseconds`}::interval
AND "cancelledAt" > now() - ${`${WALLET_RETRY_BEFORE_MS} milliseconds`}::interval
AND "lockedAt" IS NULL
AND "paymentAttempt" < $4
AND "paymentAttempt" < ${WALLET_MAX_RETRIES}
ORDER BY id DESC
FOR UPDATE SKIP LOCKED
)
Expand All @@ -496,11 +494,7 @@ const resolvers = {
now() + interval '15 minutes'
FROM failed
)
SELECT * FROM failed`,
me.id,
`${WALLET_RETRY_AFTER_MS} milliseconds`,
`${WALLET_RETRY_BEFORE_MS} milliseconds`,
WALLET_MAX_RETRIES)
SELECT * FROM failed`
}
},
Wallet: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- AlterTable
ALTER TABLE "Invoice" ADD COLUMN "paymentAttempt" INTEGER NOT NULL DEFAULT 0;
ALTER TABLE "Invoice" ADD COLUMN "lockedAt" TIMESTAMP(3);
CREATE INDEX "Invoice_cancelledAt_idx" ON "Invoice"("cancelledAt");
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ model Invoice {
@@index([confirmedIndex], map: "Invoice.confirmedIndex_index")
@@index([isHeld])
@@index([confirmedAt])
@@index([cancelledAt])
@@index([actionType])
@@index([actionState])
}
Expand Down

0 comments on commit ccbde0d

Please sign in to comment.