forked from nrabulinski/attic
server: Allow configuring max database connections
We set it to 20 by default. The SQLx default is 10.
This commit is contained in:
parent
fce89f4c95
commit
9fdec3397d
|
@ -129,6 +129,10 @@ pub struct DatabaseConfig {
|
|||
/// If enabled, a heartbeat query will be sent every minute.
|
||||
#[serde(default = "default_db_heartbeat")]
|
||||
pub heartbeat: bool,
|
||||
|
||||
/// The maximum number of concurrent connections to maintain.
|
||||
#[serde(default = "default_db_max_connections")]
|
||||
pub max_connections: u32,
|
||||
}
|
||||
|
||||
/// File storage configuration.
|
||||
|
@ -315,6 +319,10 @@ fn default_db_heartbeat() -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
fn default_db_max_connections() -> u32 {
|
||||
20
|
||||
}
|
||||
|
||||
fn default_soft_delete_caches() -> bool {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ use axum::{
|
|||
http::{uri::Scheme, Uri},
|
||||
Router,
|
||||
};
|
||||
use sea_orm::{query::Statement, ConnectionTrait, Database, DatabaseConnection};
|
||||
use sea_orm::{query::Statement, ConnectionTrait, ConnectOptions, Database, DatabaseConnection};
|
||||
use tokio::sync::OnceCell;
|
||||
use tokio::time;
|
||||
use tower_http::catch_panic::CatchPanicLayer;
|
||||
|
@ -105,7 +105,11 @@ impl StateInner {
|
|||
async fn database(&self) -> ServerResult<&DatabaseConnection> {
|
||||
self.database
|
||||
.get_or_try_init(|| async {
|
||||
Database::connect(&self.config.database.url)
|
||||
let options = ConnectOptions::new(self.config.database.url.to_owned())
|
||||
.max_connections(self.config.database.max_connections)
|
||||
.to_owned();
|
||||
|
||||
Database::connect(options)
|
||||
.await
|
||||
.map_err(ServerError::database_error)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue