Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit fca6560

Browse files
authored
feat(db): make connection pool size configurable (#613)
* feat(db): make connection pool size configurable * Fmt
1 parent a6d8b41 commit fca6560

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

config.template.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ password = "root"
1010
### networks can run within the same MongoDB instance.
1111
database_name = "chronicle"
1212

13+
### The minimum amount of connections in the pool.
14+
min_pool_size = 2
15+
1316
[api]
1417
### Whether API requests will be served.
1518
enabled = true

src/db/mongodb.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ impl MongoDb {
3131
let mut client_options = ClientOptions::parse(&config.connect_url).await?;
3232

3333
client_options.app_name = Some("Chronicle".to_string());
34+
client_options.min_pool_size = config.min_pool_size;
3435

3536
if let (Some(username), Some(password)) = (&config.username, &config.password) {
3637
let credential = Credential::builder()
@@ -153,6 +154,8 @@ pub struct MongoDbConfig {
153154
pub password: Option<String>,
154155
/// The name of the database to connect to.
155156
pub database_name: String,
157+
/// The minimum amount of connections in the pool.
158+
pub min_pool_size: Option<u32>,
156159
}
157160

158161
impl Default for MongoDbConfig {
@@ -162,6 +165,7 @@ impl Default for MongoDbConfig {
162165
username: None,
163166
password: None,
164167
database_name: MongoDb::DEFAULT_NAME.to_string(),
168+
min_pool_size: None,
165169
}
166170
}
167171
}

0 commit comments

Comments
 (0)