Skip to content

Commit fd07d28

Browse files
committed
Split store_transactions in several database transactions.
1 parent f3c9350 commit fd07d28

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

mithril-aggregator/src/database/repository/cardano_transaction_repository.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,19 @@ impl TransactionStore for CardanoTransactionRepository {
242242
}
243243

244244
async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()> {
245-
self.connection.execute("BEGIN TRANSACTION;")?;
246-
// Chunk transactions to avoid an error when we exceed sqlite binding limitations
247-
for transactions_in_chunk in transactions.chunks(100) {
248-
self.create_transactions(transactions_in_chunk.to_vec())
249-
.await
250-
.with_context(|| "CardanoTransactionRepository can not store transactions")?;
245+
const DB_TRANSACTION_SIZE: usize = 100000;
246+
for transactions_in_db_transaction_chunk in transactions.chunks(DB_TRANSACTION_SIZE) {
247+
self.connection.execute("BEGIN TRANSACTION;")?;
248+
249+
// Chunk transactions to avoid an error when we exceed sqlite binding limitations
250+
for transactions_in_chunk in transactions_in_db_transaction_chunk.chunks(100) {
251+
self.create_transactions(transactions_in_chunk.to_vec())
252+
.await
253+
.with_context(|| "CardanoTransactionRepository can not store transactions")?;
254+
}
255+
256+
self.connection.execute("END TRANSACTION;")?;
251257
}
252-
self.connection.execute("END TRANSACTION;")?;
253258
Ok(())
254259
}
255260

mithril-signer/src/database/repository/cardano_transaction_repository.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,18 @@ impl TransactionStore for CardanoTransactionRepository {
236236
}
237237

238238
async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()> {
239-
// Chunk transactions to avoid an error when we exceed sqlite binding limitations
240-
for transactions_in_chunk in transactions.chunks(100) {
241-
self.create_transactions(transactions_in_chunk.to_vec())
242-
.await
243-
.with_context(|| "CardanoTransactionRepository can not store transactions")?;
239+
const DB_TRANSACTION_SIZE: usize = 100000;
240+
for transactions_in_db_transaction_chunk in transactions.chunks(DB_TRANSACTION_SIZE) {
241+
self.connection.execute("BEGIN TRANSACTION;")?;
242+
243+
// Chunk transactions to avoid an error when we exceed sqlite binding limitations
244+
for transactions_in_chunk in transactions_in_db_transaction_chunk.chunks(100) {
245+
self.create_transactions(transactions_in_chunk.to_vec())
246+
.await
247+
.with_context(|| "CardanoTransactionRepository can not store transactions")?;
248+
}
249+
250+
self.connection.execute("END TRANSACTION;")?;
244251
}
245252
Ok(())
246253
}

0 commit comments

Comments
 (0)