From 2e79b2a871d29a9a20001749d4bf45b8d544220d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 20 May 2019 14:41:15 +0200 Subject: [PATCH] feat: Expose the sled compression setting --- meilidb-data/Cargo.toml | 4 ++++ meilidb-data/src/database/mod.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/meilidb-data/Cargo.toml b/meilidb-data/Cargo.toml index 0c5ff9f5e..751ee7fde 100644 --- a/meilidb-data/Cargo.toml +++ b/meilidb-data/Cargo.toml @@ -28,5 +28,9 @@ rev = "40b3d48" git = "https://github.com/Kerollmops/fst.git" branch = "arc-byte-slice" +[features] +default = [] +compression = ["sled/compression"] + [dev-dependencies] tempfile = "3.0.7" diff --git a/meilidb-data/src/database/mod.rs b/meilidb-data/src/database/mod.rs index dcdc13bd2..9a2306ae7 100644 --- a/meilidb-data/src/database/mod.rs +++ b/meilidb-data/src/database/mod.rs @@ -41,6 +41,18 @@ impl Database { Ok(Database { cache, inner }) } + pub fn start_with_compression>(path: P, factor: i32) -> Result { + let config = sled::ConfigBuilder::default() + .use_compression(true) + .compression_factor(factor) + .path(path) + .build(); + + let cache = RwLock::new(HashMap::new()); + let inner = sled::Db::start(config)?; + Ok(Database { cache, inner }) + } + pub fn indexes(&self) -> Result>, Error> { let bytes = match self.inner.get("indexes")? { Some(bytes) => bytes,