Skip to content

Commit 794a8f7

Browse files
committed
perf: optimize storage of block range roots
Flush buffer every 100 root computed to avoid insert queries with more than sqlite max allowed variables.
1 parent 0673352 commit 794a8f7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mithril-aggregator/src/services/cardano_transactions_importer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::mem;
12
use std::ops::Range;
23
use std::path::{Path, PathBuf};
34
use std::sync::Arc;
@@ -155,6 +156,14 @@ impl CardanoTransactionsImporter {
155156

156157
let merkle_root = MKTree::new(&transactions)?.compute_root()?;
157158
block_ranges_with_merkle_root.push((block_range, merkle_root));
159+
160+
if block_ranges_with_merkle_root.len() >= 100 {
161+
let block_ranges_with_merkle_root_save =
162+
mem::take(&mut block_ranges_with_merkle_root);
163+
self.transaction_store
164+
.store_block_range_roots(block_ranges_with_merkle_root_save)
165+
.await?;
166+
}
158167
}
159168

160169
self.transaction_store

mithril-signer/src/cardano_transactions_importer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::mem;
12
use std::ops::Range;
23
use std::path::{Path, PathBuf};
34
use std::sync::Arc;
@@ -155,6 +156,14 @@ impl CardanoTransactionsImporter {
155156

156157
let merkle_root = MKTree::new(&transactions)?.compute_root()?;
157158
block_ranges_with_merkle_root.push((block_range, merkle_root));
159+
160+
if block_ranges_with_merkle_root.len() >= 100 {
161+
let block_ranges_with_merkle_root_save =
162+
mem::take(&mut block_ranges_with_merkle_root);
163+
self.transaction_store
164+
.store_block_range_roots(block_ranges_with_merkle_root_save)
165+
.await?;
166+
}
158167
}
159168

160169
self.transaction_store

0 commit comments

Comments
 (0)