Skip to content

Commit e7e586d

Browse files
committed
db: remove premature transaction optimization
1 parent dd98012 commit e7e586d

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

src/parser/mod.rs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use std::time::{Duration, Instant};
22

3-
use diesel::connection::TransactionManager;
4-
use diesel::RunQueryDsl;
5-
63
use crate::parser::chain::ChainStorage;
74
use crate::ParserOptions;
85

@@ -56,24 +53,13 @@ impl BlockchainParser {
5653
tracing::debug!(target: "parser", "Starting worker ...");
5754

5855
self.on_start(self.cur_height);
59-
let mut conn = self.db.pool.get()?;
60-
diesel::r2d2::PoolTransactionManager::begin_transaction(&mut conn)?;
6156
while let Some(header) = self.chain_storage.get_header(self.cur_height) {
6257
Self::on_header(&header, self.cur_height);
6358
let block = self.chain_storage.get_block(self.cur_height).unwrap();
64-
self.on_block(&block, self.cur_height, &mut conn)?;
59+
self.on_block(&block, self.cur_height)?;
6560
self.print_progress(self.cur_height);
6661
self.cur_height += 1;
67-
68-
if self.cur_height % 1000 == 0 {
69-
diesel::r2d2::PoolTransactionManager::commit_transaction(&mut conn)?;
70-
drop(conn);
71-
conn = self.db.pool.get()?;
72-
diesel::r2d2::PoolTransactionManager::begin_transaction(&mut conn)?;
73-
}
7462
}
75-
diesel::r2d2::PoolTransactionManager::commit_transaction(&mut conn)?;
76-
drop(conn);
7763
self.on_complete(self.cur_height.saturating_sub(1));
7864
Ok(())
7965
}
@@ -101,23 +87,18 @@ impl BlockchainParser {
10187
&mut self,
10288
block: &bitcoin::Block,
10389
height: u64,
104-
conn: &mut diesel::r2d2::PooledConnection<
105-
diesel::r2d2::ConnectionManager<diesel::sqlite::SqliteConnection>,
106-
>,
10790
) -> anyhow::Result<()> {
10891
tracing::trace!(target: "parser", "on_block(height={}) called", height);
109-
diesel::insert_into(crate::db::schema::blocks::table)
110-
.values(crate::db::Block {
111-
height: self.cur_height.try_into()?,
112-
version: block.header.version.to_consensus(),
113-
time: block.header.time.try_into()?,
114-
encoded_target: block.header.bits.to_consensus().try_into()?,
115-
nonce: block.header.nonce.try_into()?,
116-
tx_count: block.txdata.len().try_into()?,
117-
size: block.size().try_into()?,
118-
weight: block.weight().to_wu().try_into()?,
119-
})
120-
.execute(conn)?;
92+
self.db.insert_block(crate::db::Block {
93+
height: self.cur_height.try_into()?,
94+
version: block.header.version.to_consensus(),
95+
time: block.header.time.try_into()?,
96+
encoded_target: block.header.bits.to_consensus().try_into()?,
97+
nonce: block.header.nonce.try_into()?,
98+
tx_count: block.txdata.len().try_into()?,
99+
size: block.size().try_into()?,
100+
weight: block.weight().to_wu().try_into()?,
101+
})?;
121102
Ok(())
122103
}
123104

0 commit comments

Comments
 (0)