diff --git a/src-tauri/src/commands/snapshot.rs b/src-tauri/src/commands/snapshot.rs index 8f93eaf..8ac093e 100644 --- a/src-tauri/src/commands/snapshot.rs +++ b/src-tauri/src/commands/snapshot.rs @@ -41,8 +41,10 @@ pub async fn create_snapshot( .map(|t| (t.schema.clone(), t.table.clone())) .collect(); + // Fetch FK info once — used for both dependency expansion and topological sort + let fk_rows = fetch_foreign_keys_raw(&pool).await?; + if params.include_dependencies { - let fk_rows = fetch_foreign_keys_raw(&pool).await?; for fk in &fk_rows { for (schema, table) in ¶ms.tables.iter().map(|t| (t.schema.clone(), t.table.clone())).collect::>() { if &fk.schema == schema && &fk.table == table { @@ -56,7 +58,6 @@ pub async fn create_snapshot( } // FK-based topological sort - let fk_rows = fetch_foreign_keys_raw(&pool).await?; let fk_edges: Vec<(String, String, String, String)> = fk_rows .iter() .map(|fk| (fk.schema.clone(), fk.table.clone(), fk.ref_schema.clone(), fk.ref_table.clone())) @@ -75,7 +76,7 @@ pub async fn create_snapshot( let mut total_rows: u64 = 0; for (i, (schema, table)) in sorted_tables.iter().enumerate() { - let percent = 10 + ((i as u8) * 80 / total_tables.max(1) as u8); + let percent = (10 + (i * 80 / total_tables.max(1))).min(90) as u8; let _ = app.emit( "snapshot-progress", SnapshotProgress { @@ -249,7 +250,7 @@ pub async fn restore_snapshot( continue; } - let percent = 20 + ((i as u8) * 75 / total_tables.max(1) as u8); + let percent = (20 + (i * 75 / total_tables.max(1))).min(95) as u8; let _ = app.emit( "snapshot-progress", SnapshotProgress {