Skip to content

Commit 01641cb

Browse files
committed
feat(sqlite): SqliteStoreConfig::pool_size sets a minimum to 2.
This patch updates `SqliteStoreConfig::pool_size` to be at least 2. We need 2 connections: one for write operations, one for read operations. This behaviour is coming in the next patches.
1 parent 72d1332 commit 01641cb

File tree

1 file changed

+17
-3
lines changed
  • crates/matrix-sdk-sqlite/src

1 file changed

+17
-3
lines changed

crates/matrix-sdk-sqlite/src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mod event_cache_store;
2525
mod state_store;
2626
mod utils;
2727
use std::{
28+
cmp::max,
2829
fmt,
2930
path::{Path, PathBuf},
3031
};
@@ -66,6 +67,12 @@ impl fmt::Debug for SqliteStoreConfig {
6667
}
6768
}
6869

70+
/// The minimum size of the connections pool.
71+
///
72+
/// We need at least 2 connections: one connection for write operations, and one
73+
/// connection for read operations.
74+
const POOL_MINIMUM_SIZE: usize = 2;
75+
6976
impl SqliteStoreConfig {
7077
/// Create a new [`SqliteStoreConfig`] with a path representing the
7178
/// directory containing the store database.
@@ -76,7 +83,7 @@ impl SqliteStoreConfig {
7683
Self {
7784
path: path.as_ref().to_path_buf(),
7885
passphrase: None,
79-
pool_config: PoolConfig::new(num_cpus::get_physical() * 4),
86+
pool_config: PoolConfig::new(max(POOL_MINIMUM_SIZE, num_cpus::get_physical() * 4)),
8087
runtime_config: RuntimeConfig::default(),
8188
}
8289
}
@@ -122,7 +129,7 @@ impl SqliteStoreConfig {
122129
///
123130
/// See [`deadpool_sqlite::PoolConfig::max_size`] to learn more.
124131
pub fn pool_max_size(mut self, max_size: usize) -> Self {
125-
self.pool_config.max_size = max_size;
132+
self.pool_config.max_size = max(POOL_MINIMUM_SIZE, max_size);
126133
self
127134
}
128135

@@ -218,7 +225,7 @@ mod tests {
218225
path::{Path, PathBuf},
219226
};
220227

221-
use super::SqliteStoreConfig;
228+
use super::{SqliteStoreConfig, POOL_MINIMUM_SIZE};
222229

223230
#[test]
224231
fn test_new() {
@@ -263,4 +270,11 @@ mod tests {
263270

264271
assert_eq!(store_config.path, PathBuf::from("bar"));
265272
}
273+
274+
#[test]
275+
fn test_pool_size_has_a_minimum() {
276+
let store_config = SqliteStoreConfig::new(Path::new("foo")).pool_max_size(1);
277+
278+
assert_eq!(store_config.pool_config.max_size, POOL_MINIMUM_SIZE);
279+
}
266280
}

0 commit comments

Comments
 (0)