Skip to content

Commit 0253877

Browse files
reivilibresandhose
authored andcommitted
Add a progress bar for the index/constraint rebuilds
1 parent b626753 commit 0253877

File tree

1 file changed

+18
-1
lines changed
  • crates/syn2mas/src/mas_writer

1 file changed

+18
-1
lines changed

crates/syn2mas/src/mas_writer/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use sqlx::{query, query_as, Executor, PgConnection};
2222
use thiserror::Error;
2323
use thiserror_ext::{Construct, ContextInto};
2424
use tokio::sync::mpsc::{self, Receiver, Sender};
25-
use tracing::{error, info, warn, Level};
25+
use tracing::{error, info, warn, Level, Span};
26+
use tracing_indicatif::{span_ext::IndicatifSpanExt, style::ProgressStyle};
2627
use uuid::Uuid;
2728

2829
use self::{
@@ -538,21 +539,37 @@ impl<'conn> MasWriter<'conn> {
538539
Ok((indices_to_restore, constraints_to_restore))
539540
}
540541

542+
#[tracing::instrument(skip_all, fields(indicatif.pb_show))]
541543
async fn restore_indices(
542544
conn: &mut LockedMasDatabase<'_>,
543545
indices_to_restore: &[IndexDescription],
544546
constraints_to_restore: &[ConstraintDescription],
545547
) -> Result<(), Error> {
548+
let span = Span::current();
549+
// TODO this style is a quick workaround for showing the message, but
550+
// might not be optimal for other purposes
551+
span.pb_set_style(
552+
&ProgressStyle::with_template(
553+
"[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}",
554+
)
555+
.unwrap(),
556+
);
557+
span.pb_set_length((indices_to_restore.len() + constraints_to_restore.len()) as u64);
558+
546559
// First restore all indices. The order is not important as far as I know.
547560
// However the indices are needed before constraints.
548561
for index in indices_to_restore.iter().rev() {
562+
span.pb_set_message(&format!("building index: {}", &index.name));
549563
constraint_pausing::restore_index(conn.as_mut(), index).await?;
564+
span.pb_inc(1);
550565
}
551566
// Then restore all constraints.
552567
// The order here is the reverse of drop order, since some constraints may rely
553568
// on other constraints to work.
554569
for constraint in constraints_to_restore.iter().rev() {
570+
span.pb_set_message(&format!("building constraint: {}", &constraint.name));
555571
constraint_pausing::restore_constraint(conn.as_mut(), constraint).await?;
572+
span.pb_inc(1);
556573
}
557574
Ok(())
558575
}

0 commit comments

Comments
 (0)