Skip to content

Commit 66293f7

Browse files
reivilibresandhose
authored andcommitted
Add a progress bar for the index/constraint rebuilds
1 parent e081c20 commit 66293f7

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::{Executor, PgConnection, query, query_as};
2222
use thiserror::Error;
2323
use thiserror_ext::{Construct, ContextInto};
2424
use tokio::sync::mpsc::{self, Receiver, Sender};
25-
use tracing::{Level, error, info, warn};
25+
use tracing::{Level, Span, error, info, warn};
26+
use tracing_indicatif::{span_ext::IndicatifSpanExt, style::ProgressStyle};
2627
use uuid::Uuid;
2728

2829
use self::{
@@ -542,21 +543,37 @@ impl MasWriter {
542543
Ok((indices_to_restore, constraints_to_restore))
543544
}
544545

546+
#[tracing::instrument(skip_all, fields(indicatif.pb_show))]
545547
async fn restore_indices(
546548
conn: &mut LockedMasDatabase,
547549
indices_to_restore: &[IndexDescription],
548550
constraints_to_restore: &[ConstraintDescription],
549551
) -> Result<(), Error> {
552+
let span = Span::current();
553+
// TODO this style is a quick workaround for showing the message, but
554+
// might not be optimal for other purposes
555+
span.pb_set_style(
556+
&ProgressStyle::with_template(
557+
"[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}",
558+
)
559+
.unwrap(),
560+
);
561+
span.pb_set_length((indices_to_restore.len() + constraints_to_restore.len()) as u64);
562+
550563
// First restore all indices. The order is not important as far as I know.
551564
// However the indices are needed before constraints.
552565
for index in indices_to_restore.iter().rev() {
566+
span.pb_set_message(&format!("building index: {}", &index.name));
553567
constraint_pausing::restore_index(conn.as_mut(), index).await?;
568+
span.pb_inc(1);
554569
}
555570
// Then restore all constraints.
556571
// The order here is the reverse of drop order, since some constraints may rely
557572
// on other constraints to work.
558573
for constraint in constraints_to_restore.iter().rev() {
574+
span.pb_set_message(&format!("building constraint: {}", &constraint.name));
559575
constraint_pausing::restore_constraint(conn.as_mut(), constraint).await?;
576+
span.pb_inc(1);
560577
}
561578
Ok(())
562579
}

0 commit comments

Comments
 (0)