Server: Adds the optimize command

pull/428/head
Tpt 2 years ago committed by Thomas Tanon
parent 3d61867386
commit 23e47bcc5e
  1. 23
      server/src/main.rs

@ -192,6 +192,11 @@ enum Command {
#[arg(long)] #[arg(long)]
update_base: Option<String>, update_base: Option<String>,
}, },
/// 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<()> { pub fn main() -> anyhow::Result<()> {
@ -565,6 +570,15 @@ pub fn main() -> anyhow::Result<()> {
store.update(update)?; store.update(update)?;
Ok(()) 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] #[test]
fn cli_load_and_dump_graph() -> Result<()> { fn cli_load_optimize_and_dump_graph() -> Result<()> {
let store_dir = TempDir::new()?; let store_dir = TempDir::new()?;
let input_file = NamedTempFile::new("input.nt")?; let input_file = NamedTempFile::new("input.nt")?;
input_file input_file
@ -1645,6 +1659,13 @@ mod tests {
.assert() .assert()
.success(); .success();
cli_command()?
.arg("optimize")
.arg("--location")
.arg(store_dir.path())
.assert()
.success();
let output_file = NamedTempFile::new("output.nt")?; let output_file = NamedTempFile::new("output.nt")?;
cli_command()? cli_command()?
.arg("dump") .arg("dump")

Loading…
Cancel
Save