From 9ff5ce0d372c627205e11c107aaa73cb06c22ab2 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Wed, 21 Jun 2023 19:54:02 -0400 Subject: [PATCH] Change order of cpfp db operations --- backend/src/repositories/CpfpRepository.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/src/repositories/CpfpRepository.ts b/backend/src/repositories/CpfpRepository.ts index 1ad80864b..90ba2ac80 100644 --- a/backend/src/repositories/CpfpRepository.ts +++ b/backend/src/repositories/CpfpRepository.ts @@ -78,14 +78,6 @@ class CpfpRepository { const maxChunk = 100; let chunkIndex = 0; - // insert transactions in batches of up to 100 rows - while (chunkIndex < txs.length) { - const chunk = txs.slice(chunkIndex, chunkIndex + maxChunk); - await transactionRepository.$batchSetCluster(chunk); - chunkIndex += maxChunk; - } - - chunkIndex = 0; // insert clusters in batches of up to 100 rows while (chunkIndex < clusterValues.length) { const chunk = clusterValues.slice(chunkIndex, chunkIndex + maxChunk); @@ -103,6 +95,15 @@ class CpfpRepository { ); chunkIndex += maxChunk; } + + chunkIndex = 0; + // insert transactions in batches of up to 100 rows + while (chunkIndex < txs.length) { + const chunk = txs.slice(chunkIndex, chunkIndex + maxChunk); + await transactionRepository.$batchSetCluster(chunk); + chunkIndex += maxChunk; + } + return true; } catch (e: any) { logger.err(`Cannot save cpfp clusters into db. Reason: ` + (e instanceof Error ? e.message : e));