feat: configurable cache capacity

This commit is contained in:
Timo Kösters 2020-10-21 21:43:59 +02:00
parent 6dbe195695
commit 6b3934e31d
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
2 changed files with 16 additions and 5 deletions

View file

@ -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 {