Check database health: report size and run VACUUM to reclaim space. The DB path is taken from the opened instance so the size measured is the same file (possibly a branch-specific DB) that VACUUM actually compacts.
(dc: &mut DoctorCounters, project_path: &Path)
| 132 | /// The DB path is taken from the opened instance so the size measured is the |
| 133 | /// same file (possibly a branch-specific DB) that VACUUM actually compacts. |
| 134 | async fn check_database(dc: &mut DoctorCounters, project_path: &Path) { |
| 135 | let ts = match TraceDecay::open(project_path).await { |
| 136 | Ok(ts) => ts, |
| 137 | Err(e) => { |
| 138 | dc.fail(&format!("Could not open database: {e}")); |
| 139 | return; |
| 140 | } |
| 141 | }; |
| 142 | let db_path = ts.db_path(); |
| 143 | let size_before = std::fs::metadata(&db_path).map_or(0, |m| m.len()); |
| 144 | |
| 145 | dc.pass(&format!("DB size: {}", format_bytes(size_before))); |
| 146 | |
| 147 | eprintln!(" Compacting database (VACUUM)…"); |
| 148 | match ts.optimize().await { |
| 149 | Ok(()) => { |
| 150 | let size_after = std::fs::metadata(&db_path).map_or(size_before, |m| m.len()); |
| 151 | if size_before > size_after { |
| 152 | let reclaimed = size_before - size_after; |
| 153 | dc.pass(&format!( |
| 154 | "Compacted: {} → {} (reclaimed {})", |
| 155 | format_bytes(size_before), |
| 156 | format_bytes(size_after), |
| 157 | format_bytes(reclaimed), |
| 158 | )); |
| 159 | } else { |
| 160 | dc.pass("Database already compact"); |
| 161 | } |
| 162 | } |
| 163 | Err(e) => { |
| 164 | dc.warn(&format!("VACUUM failed: {e}")); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /// Check binary location and version. |
| 170 | fn check_binary(dc: &mut DoctorCounters) { |