backend: reduce number of concurrent db connections

This commit is contained in:
2025-10-16 11:10:53 +02:00
parent 05dffec42e
commit 44b59edcb3
4 changed files with 22 additions and 14 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ async fn main() -> anyhow::Result<()> {
init_tracing();
let config = AppConfig::from_env()?;
let pool = db::init_pool(&config.database_url)?;
let pool = db::init_pool_with_size(&config.database_url, 1)?;
let s3_client = build_client(&config).await?;
let storage = Arc::new(S3Storage::new(s3_client, config.s3_bucket.clone()));
let jwt = JwtService::from_config(&config)?;
+8 -1
View File
@@ -5,10 +5,17 @@ use diesel::r2d2::{ConnectionManager, Pool};
pub type PgPool = Pool<ConnectionManager<PgConnection>>;
const DEFAULT_MAX_POOL_SIZE: u32 = 2;
pub fn init_pool(database_url: &str) -> anyhow::Result<PgPool> {
init_pool_with_size(database_url, DEFAULT_MAX_POOL_SIZE)
}
pub fn init_pool_with_size(database_url: &str, max_size: u32) -> anyhow::Result<PgPool> {
let manager = ConnectionManager::<PgConnection>::new(database_url);
let pool_size = max_size.max(1);
let pool = Pool::builder()
.max_size(16)
.max_size(pool_size)
.connection_timeout(Duration::from_secs(10))
.build(manager)?;
Ok(pool)