From 8af196dc6f3b3b963fb20d8535f183e20f845a4c Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Thu, 8 Sep 2022 14:34:15 -0700 Subject: [PATCH] Commit every 1000 blocks instead of every block (#496) --- src/index.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/index.rs b/src/index.rs index f76d01c6d1..959c9b0491 100644 --- a/src/index.rs +++ b/src/index.rs @@ -122,6 +122,9 @@ impl Index { } pub(crate) fn index_ranges(&self) -> Result { + let mut block = 0; + let mut wtx = self.database.begin_write()?; + loop { if let Some(height_limit) = self.height_limit { if self.height()? >= height_limit { @@ -129,17 +132,22 @@ impl Index { } } - let mut wtx = self.database.begin_write()?; - let done = self.index_block(&mut wtx)?; - wtx.commit()?; + if block % 1000 == 0 { + wtx.commit()?; + wtx = self.database.begin_write()?; + } if done || INTERRUPTS.load(atomic::Ordering::Relaxed) > 0 { break; } + + block += 1; } + wtx.commit()?; + Ok(()) }