Skip to content

Commit

Permalink
feat(db): make connection pool size configurable (#613)
Browse files Browse the repository at this point in the history
* feat(db): make connection pool size configurable

* Fmt
  • Loading branch information
grtlr authored Aug 30, 2022
1 parent a6d8b41 commit fca6560
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ password = "root"
### networks can run within the same MongoDB instance.
database_name = "chronicle"

### The minimum amount of connections in the pool.
min_pool_size = 2

[api]
### Whether API requests will be served.
enabled = true
Expand Down
4 changes: 4 additions & 0 deletions src/db/mongodb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl MongoDb {
let mut client_options = ClientOptions::parse(&config.connect_url).await?;

client_options.app_name = Some("Chronicle".to_string());
client_options.min_pool_size = config.min_pool_size;

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

impl Default for MongoDbConfig {
Expand All @@ -162,6 +165,7 @@ impl Default for MongoDbConfig {
username: None,
password: None,
database_name: MongoDb::DEFAULT_NAME.to_string(),
min_pool_size: None,
}
}
}

0 comments on commit fca6560

Please sign in to comment.