Skip to content

Commit

Permalink
Prevent progress bar from flickering when synced (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Nov 2, 2022
1 parent ab3fde8 commit 3c50e67
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ impl Updater {
index: &'index Index,
mut wtx: WriteTransaction<'index>,
) -> Result {
let mut progress_bar = if cfg!(test) || log_enabled!(log::Level::Info) {
None
} else {
let progress_bar = ProgressBar::new(index.client.get_block_count()?);
progress_bar.set_position(self.height);
progress_bar.set_style(
ProgressStyle::with_template("[indexing blocks] {wide_bar} {pos}/{len}").unwrap(),
);
Some(progress_bar)
};
let starting_height = index.client.get_block_count()? + 1;

let mut progress_bar =
if cfg!(test) || log_enabled!(log::Level::Info) || starting_height <= self.height {
None
} else {
let progress_bar = ProgressBar::new(starting_height);
progress_bar.set_position(self.height);
progress_bar.set_style(
ProgressStyle::with_template("[indexing blocks] {wide_bar} {pos}/{len}").unwrap(),
);
Some(progress_bar)
};

let rx = Self::fetch_blocks_from(
index,
Expand All @@ -73,7 +76,7 @@ impl Updater {
progress_bar.inc(1);

if progress_bar.position() > progress_bar.length().unwrap() {
progress_bar.set_length(index.client.get_block_count()?);
progress_bar.set_length(index.client.get_block_count()? + 1);
}
}

Expand Down

0 comments on commit 3c50e67

Please sign in to comment.