From 6b3934e31da101873369984af0a4ca1ec6ac574d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Wed, 21 Oct 2020 21:43:59 +0200 Subject: [PATCH] feat: configurable cache capacity --- Cargo.toml | 2 +- src/database.rs | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9e23c36..8b29be8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ state-res = { git = "https://github.com/timokoesters/state-res", branch = "spec- # Used for long polling tokio = "0.2.22" # Used for storing data permanently -sled = "0.34.4" +sled = { version = "0.34.4", default-features = false } # Used for emitting log entries log = "0.4.11" # Used for rocket<->ruma conversions diff --git a/src/database.rs b/src/database.rs index 6bdc32a..883ef85 100644 --- a/src/database.rs +++ b/src/database.rs @@ -10,12 +10,11 @@ pub mod users; use crate::{Error, Result}; use directories::ProjectDirs; -use log::info; -use std::fs::remove_dir_all; - use futures::StreamExt; +use log::info; use rocket::{futures, Config}; use ruma::{DeviceId, UserId}; +use std::{convert::TryFrom, fs::remove_dir_all}; pub struct Database { pub globals: globals::Globals, @@ -66,7 +65,19 @@ impl Database { .to_owned()) })?; - let db = sled::open(&path)?; + let db = sled::Config::default() + .path(&path) + .cache_capacity( + u64::try_from( + config + .get_int("cache_capacity") + .unwrap_or(1024 * 1024 * 1024), + ) + .map_err(|_| Error::BadConfig("Cache capacity needs to be a u64."))?, + ) + .print_profile_on_drop(false) + .open()?; + info!("Opened sled database at {}", path); Ok(Self {