mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-06 03:20:53 +00:00
feat: improve connection pool settings
This commit is contained in:
parent
f9789aacff
commit
724e012223
1 changed files with 15 additions and 12 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use portfolio_core::{sea_orm::{self}};
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use portfolio_core::sea_orm::{self};
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
use sea_orm::ConnectOptions;
|
use sea_orm::ConnectOptions;
|
||||||
use sea_orm_rocket::{rocket::figment::Figment, Database};
|
use sea_orm_rocket::{rocket::figment::Figment, Database};
|
||||||
|
|
@ -36,17 +36,20 @@ impl sea_orm_rocket::Pool for SeaOrmPool {
|
||||||
let mut options: ConnectOptions = database_url.into();
|
let mut options: ConnectOptions = database_url.into();
|
||||||
options
|
options
|
||||||
.max_connections(1024)
|
.max_connections(1024)
|
||||||
.min_connections(0)
|
.min_connections(5)
|
||||||
.connect_timeout(Duration::from_secs(3))
|
.connect_timeout(Duration::from_secs(15))
|
||||||
|
.acquire_timeout(Duration::from_secs(15))
|
||||||
|
.max_lifetime(Duration::from_secs(15))
|
||||||
|
.idle_timeout(Duration::from_secs(5))
|
||||||
.sqlx_logging(false);
|
.sqlx_logging(false);
|
||||||
|
|
||||||
/* options
|
/* options
|
||||||
.max_connections(config.max_connections as u32)
|
.max_connections(config.max_connections as u32)
|
||||||
.min_connections(config.min_connections.unwrap_or_default())
|
.min_connections(config.min_connections.unwrap_or_default())
|
||||||
.connect_timeout(Duration::from_secs(config.connect_timeout));
|
.connect_timeout(Duration::from_secs(config.connect_timeout));
|
||||||
if let Some(idle_timeout) = config.idle_timeout {
|
if let Some(idle_timeout) = config.idle_timeout {
|
||||||
options.idle_timeout(Duration::from_secs(idle_timeout));
|
options.idle_timeout(Duration::from_secs(idle_timeout));
|
||||||
} */
|
} */
|
||||||
|
|
||||||
let conn = sea_orm::Database::connect(options).await?;
|
let conn = sea_orm::Database::connect(options).await?;
|
||||||
|
|
||||||
|
|
@ -56,4 +59,4 @@ impl sea_orm_rocket::Pool for SeaOrmPool {
|
||||||
fn borrow(&self) -> &Self::Connection {
|
fn borrow(&self) -> &Self::Connection {
|
||||||
&self.conn
|
&self.conn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue