mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 16:21:24 +01:00
remove database's dependency on entire Config
This makes it easier to ad-hoc construct databases, e.g. in a CLI tool that operates on multiple database instances.
This commit is contained in:
parent
14b0769a3e
commit
b3d9cd5e9c
5 changed files with 89 additions and 54 deletions
|
|
@ -12,7 +12,7 @@ use thread_local::ThreadLocal;
|
|||
use tracing::debug;
|
||||
|
||||
use super::{watchers::Watchers, KeyValueDatabaseEngine, KvTree};
|
||||
use crate::{database::Config, Result};
|
||||
use crate::Result;
|
||||
|
||||
thread_local! {
|
||||
static READ_CONNECTION: RefCell<Option<&'static Connection>> =
|
||||
|
|
@ -66,10 +66,14 @@ pub(crate) struct Engine {
|
|||
}
|
||||
|
||||
impl Engine {
|
||||
pub(crate) fn open(config: &Config) -> Result<Self> {
|
||||
let path = Path::new(&config.database.path).join(format!(
|
||||
pub(crate) fn open(
|
||||
path: &Path,
|
||||
cache_capacity_mb: f64,
|
||||
conduit_compat: bool,
|
||||
) -> Result<Self> {
|
||||
let path = path.join(format!(
|
||||
"{}.db",
|
||||
if config.conduit_compat {
|
||||
if conduit_compat {
|
||||
"conduit"
|
||||
} else {
|
||||
"grapevine"
|
||||
|
|
@ -87,9 +91,9 @@ impl Engine {
|
|||
clippy::cast_precision_loss,
|
||||
clippy::cast_sign_loss
|
||||
)]
|
||||
let cache_size_per_thread =
|
||||
((config.database.cache_capacity_mb * 1024.0)
|
||||
/ ((num_cpus::get() as f64 * 2.0) + 1.0)) as u32;
|
||||
let cache_size_per_thread = ((cache_capacity_mb * 1024.0)
|
||||
/ ((num_cpus::get() as f64 * 2.0) + 1.0))
|
||||
as u32;
|
||||
|
||||
let writer =
|
||||
Mutex::new(Engine::prepare_conn(&path, cache_size_per_thread)?);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue