Add vacuum method to Indexer for database maintenance

- Added a `vacuum` method in `database.rs` to optimize database file size and performance.
- Integrated `vacuum` calls into `scan.rs` and `index.rs` to ensure regular maintenance during operations.
This commit is contained in:
elipeter 2025-06-17 21:00:24 +02:00
parent 0a62b6f40c
commit eedfc5dbe8
3 changed files with 17 additions and 1 deletions

View file

@ -81,5 +81,11 @@ pub fn build_index(
idx.replace_issues(file_id, rows).unwrap();
Ok(())
}).unwrap();
{
let idx = Indexer::from_pool(&project_name, &pool)?;
idx.vacuum()?;
}
Ok(())
}

View file

@ -139,6 +139,11 @@ fn scan_with_index_parallel(
Ok(())
}).unwrap();
{
let idx = Indexer::from_pool(project, &pool)?;
idx.vacuum()?;
}
Ok(acc.into_inner().unwrap())
}

View file

@ -211,10 +211,15 @@ pub mod index {
VACUUM;
"#,
)?;
self.c().execute_batch(SCHEMA)?;
Ok(())
}
pub fn vacuum(&self) -> rusqlite::Result<()> {
self.c().execute("VACUUM;", [])?;
Ok(())
}
fn digest_file(path: &Path) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
let mut hasher = blake3::Hasher::new();