From bca49aed2a8cdaeb66b1c1da7f7e5a93df2aad25 Mon Sep 17 00:00:00 2001 From: dal Date: Wed, 16 Apr 2025 07:19:24 -0600 Subject: [PATCH] search pool fix --- api/libs/database/src/pool.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/api/libs/database/src/pool.rs b/api/libs/database/src/pool.rs index 44f760df3..9f291912e 100644 --- a/api/libs/database/src/pool.rs +++ b/api/libs/database/src/pool.rs @@ -21,12 +21,24 @@ static REDIS_POOL: OnceCell = OnceCell::new(); pub async fn init_pools() -> Result<()> { let diesel_pool = match establish_diesel_connection().await { - Ok(pool) => pool, + Ok(pool) => { + // Warm up Diesel pool by acquiring min_idle connections + for _ in 0..5 { + let _ = pool.get().await; + } + pool + }, Err(e) => return Err(anyhow!("Failed to establish diesel connection: {}", e)), }; let sqlx_pool = match establish_sqlx_connection().await { - Ok(pool) => pool, + Ok(pool) => { + // Warm up SQLx pool by acquiring min_connections connections + for _ in 0..5 { + let _ = pool.acquire().await; + } + pool + }, Err(e) => return Err(anyhow!("Failed to establish sqlx connection: {}", e)), };