MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / check_database

Function check_database

src/doctor.rs:134–167  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
134async 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.
170fn check_binary(dc: &mut DoctorCounters) {

Callers 1

run_doctorFunction · 0.85

Calls 5

failMethod · 0.80
passMethod · 0.80
warnMethod · 0.80
db_pathMethod · 0.45
optimizeMethod · 0.45

Tested by

no test coverage detected