Skip to content

Commit

Permalink
Split store_transactions in several database transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfauvel committed May 6, 2024
1 parent f3c9350 commit fd07d28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,19 @@ impl TransactionStore for CardanoTransactionRepository {
}

async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()> {
self.connection.execute("BEGIN TRANSACTION;")?;
// Chunk transactions to avoid an error when we exceed sqlite binding limitations
for transactions_in_chunk in transactions.chunks(100) {
self.create_transactions(transactions_in_chunk.to_vec())
.await
.with_context(|| "CardanoTransactionRepository can not store transactions")?;
const DB_TRANSACTION_SIZE: usize = 100000;
for transactions_in_db_transaction_chunk in transactions.chunks(DB_TRANSACTION_SIZE) {
self.connection.execute("BEGIN TRANSACTION;")?;

// Chunk transactions to avoid an error when we exceed sqlite binding limitations
for transactions_in_chunk in transactions_in_db_transaction_chunk.chunks(100) {
self.create_transactions(transactions_in_chunk.to_vec())
.await
.with_context(|| "CardanoTransactionRepository can not store transactions")?;
}

self.connection.execute("END TRANSACTION;")?;
}
self.connection.execute("END TRANSACTION;")?;
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,18 @@ impl TransactionStore for CardanoTransactionRepository {
}

async fn store_transactions(&self, transactions: Vec<CardanoTransaction>) -> StdResult<()> {
// Chunk transactions to avoid an error when we exceed sqlite binding limitations
for transactions_in_chunk in transactions.chunks(100) {
self.create_transactions(transactions_in_chunk.to_vec())
.await
.with_context(|| "CardanoTransactionRepository can not store transactions")?;
const DB_TRANSACTION_SIZE: usize = 100000;
for transactions_in_db_transaction_chunk in transactions.chunks(DB_TRANSACTION_SIZE) {
self.connection.execute("BEGIN TRANSACTION;")?;

// Chunk transactions to avoid an error when we exceed sqlite binding limitations
for transactions_in_chunk in transactions_in_db_transaction_chunk.chunks(100) {
self.create_transactions(transactions_in_chunk.to_vec())
.await
.with_context(|| "CardanoTransactionRepository can not store transactions")?;
}

self.connection.execute("END TRANSACTION;")?;
}
Ok(())
}
Expand Down

0 comments on commit fd07d28

Please sign in to comment.