Skip to content

Commit 4f1ea76

Browse files
reivilibresandhose
authored andcommitted
Add a progress bar for the index/constraint rebuilds
1 parent 24d4d09 commit 4f1ea76

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::{
@@ -539,21 +540,37 @@ impl MasWriter {
539540
Ok((indices_to_restore, constraints_to_restore))
540541
}
541542

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

0 commit comments

Comments
 (0)