From 23e47bcc5e1caa9b39da3c26590b27c3a4777418 Mon Sep 17 00:00:00 2001 From: Tpt Date: Tue, 14 Mar 2023 17:54:56 +0100 Subject: [PATCH] Server: Adds the optimize command --- server/src/main.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/server/src/main.rs b/server/src/main.rs index 8cdbc952..b30b963a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -192,6 +192,11 @@ enum Command { #[arg(long)] update_base: Option, }, + /// Optimizes the database storage. + /// + /// Done by default in the background when serving requests. + /// It is likely to not be useful in most of cases except if you provide a read-only SPARQL endpoint under heavy oad. + Optimize {}, } pub fn main() -> anyhow::Result<()> { @@ -565,6 +570,15 @@ pub fn main() -> anyhow::Result<()> { store.update(update)?; Ok(()) } + Command::Optimize {} => { + let store = Store::open( + matches + .location + .ok_or_else(|| anyhow!("The --location argument is required"))?, + )?; + store.optimize()?; + Ok(()) + } } } @@ -1631,7 +1645,7 @@ mod tests { } #[test] - fn cli_load_and_dump_graph() -> Result<()> { + fn cli_load_optimize_and_dump_graph() -> Result<()> { let store_dir = TempDir::new()?; let input_file = NamedTempFile::new("input.nt")?; input_file @@ -1645,6 +1659,13 @@ mod tests { .assert() .success(); + cli_command()? + .arg("optimize") + .arg("--location") + .arg(store_dir.path()) + .assert() + .success(); + let output_file = NamedTempFile::new("output.nt")?; cli_command()? .arg("dump")