Skip to content

Commit 1ca5b0e

Browse files
committed
replace NOT IN usage with IN to avoid seq scans
1 parent afd86bb commit 1ca5b0e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

api/payIn/transitions.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { datePivot } from '@/lib/time'
2-
import { Prisma } from '@prisma/client'
2+
import { Prisma, PayInState } from '@prisma/client'
33
import { onBegin, onFail, onPaid, onPaidSideEffects } from '.'
44
import { walletLogger } from '@/wallets/server/logger'
55
import { getPaymentFailureStatus, getPaymentOrNotSent, hodlInvoiceCltvDetails } from '../lnd'
@@ -9,7 +9,10 @@ import { MIN_SETTLEMENT_CLTV_DELTA } from '@/wallets/server/wrap'
99
import { LND_PATHFINDING_TIME_PREF_PPM, LND_PATHFINDING_TIMEOUT_MS } from '@/lib/constants'
1010
import { notifyWithdrawal } from '@/lib/webPush'
1111
import { PayInFailureReasonError } from './errors'
12+
1213
export const PAY_IN_TERMINAL_STATES = ['PAID', 'FAILED']
14+
export const PAY_IN_PENDING_STATES = Object.values(PayInState).filter(state => !PAY_IN_TERMINAL_STATES.includes(state))
15+
1316
const FINALIZE_OPTIONS = { retryLimit: 2 ** 31 - 1, retryBackoff: false, retryDelay: 5, priority: 1000 }
1417

1518
async function transitionPayIn (jobName, data,

worker/payIn.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { datePivot, sleep } from '@/lib/time'
77
import retry from 'async-retry'
88
import {
99
payInWithdrawalPaid, payInWithdrawalFailed, payInPaid, payInForwarding, payInForwarded, payInFailedForward, payInHeld, payInFailed,
10-
PAY_IN_TERMINAL_STATES
10+
PAY_IN_TERMINAL_STATES,
11+
PAY_IN_PENDING_STATES
1112
} from '@/api/payIn/transitions'
1213
import { isWithdrawal } from '@/api/payIn/lib/is'
1314
import { LND_PATHFINDING_TIMEOUT_MS } from '@/lib/constants'
@@ -292,7 +293,7 @@ export async function checkPendingPayInBolt11s (args) {
292293
const { models } = args
293294
const pendingPayIns = await models.payIn.findMany({
294295
where: {
295-
payInState: { notIn: PAY_IN_TERMINAL_STATES },
296+
payInState: { in: PAY_IN_PENDING_STATES },
296297
payInBolt11: { isNot: null }
297298
},
298299
include: { payInBolt11: true }
@@ -312,7 +313,7 @@ export async function checkPendingPayOutBolt11s (args) {
312313
const { models } = args
313314
const pendingPayOuts = await models.payIn.findMany({
314315
where: {
315-
payInState: { notIn: PAY_IN_TERMINAL_STATES },
316+
payInState: { in: PAY_IN_PENDING_STATES },
316317
payOutBolt11: { isNot: null }
317318
},
318319
include: { payOutBolt11: true }

0 commit comments

Comments
 (0)