Skip to content

Commit 9ef381f

Browse files
committed
fix: batch drop mempool transactions (#1920)
1 parent 5aab1ef commit 9ef381f

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/datastore/pg-write-store.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -1809,22 +1809,24 @@ export class PgWriteStore extends PgStore {
18091809
}
18101810

18111811
async dropMempoolTxs({ status, txIds }: { status: DbTxStatus; txIds: string[] }): Promise<void> {
1812-
const updateResults = await this.sql<{ tx_id: string }[]>`
1813-
WITH pruned AS (
1814-
UPDATE mempool_txs
1815-
SET pruned = TRUE, status = ${status}
1816-
WHERE tx_id IN ${this.sql(txIds)} AND pruned = FALSE
1817-
RETURNING tx_id
1818-
),
1819-
count_update AS (
1820-
UPDATE chain_tip SET
1821-
mempool_tx_count = mempool_tx_count - (SELECT COUNT(*) FROM pruned),
1822-
mempool_updated_at = NOW()
1823-
)
1824-
SELECT tx_id FROM pruned
1825-
`;
1826-
for (const txId of updateResults.map(r => r.tx_id)) {
1827-
await this.notifier?.sendTx({ txId });
1812+
for (const batch of batchIterate(txIds, INSERT_BATCH_SIZE)) {
1813+
const updateResults = await this.sql<{ tx_id: string }[]>`
1814+
WITH pruned AS (
1815+
UPDATE mempool_txs
1816+
SET pruned = TRUE, status = ${status}
1817+
WHERE tx_id IN ${this.sql(batch)} AND pruned = FALSE
1818+
RETURNING tx_id
1819+
),
1820+
count_update AS (
1821+
UPDATE chain_tip SET
1822+
mempool_tx_count = mempool_tx_count - (SELECT COUNT(*) FROM pruned),
1823+
mempool_updated_at = NOW()
1824+
)
1825+
SELECT tx_id FROM pruned
1826+
`;
1827+
for (const txId of updateResults.map(r => r.tx_id)) {
1828+
await this.notifier?.sendTx({ txId });
1829+
}
18281830
}
18291831
}
18301832

0 commit comments

Comments
 (0)