From eedfc5dbe8a53cbac48db45bae493436caa536fd Mon Sep 17 00:00:00 2001 From: elipeter Date: Tue, 17 Jun 2025 21:00:24 +0200 Subject: [PATCH] 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. --- src/commands/index.rs | 6 ++++++ src/commands/scan.rs | 5 +++++ src/database.rs | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/commands/index.rs b/src/commands/index.rs index 1873e625..3411789d 100644 --- a/src/commands/index.rs +++ b/src/commands/index.rs @@ -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(()) } \ No newline at end of file diff --git a/src/commands/scan.rs b/src/commands/scan.rs index df23bca5..bbe87480 100644 --- a/src/commands/scan.rs +++ b/src/commands/scan.rs @@ -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()) } diff --git a/src/database.rs b/src/database.rs index 38688b86..b2e1e014 100644 --- a/src/database.rs +++ b/src/database.rs @@ -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, Box> { let mut hasher = blake3::Hasher::new();