From ce426e298521712034c3f27c36d164865ef4cb1e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 26 May 2026 20:49:17 +0000 Subject: [PATCH 1/3] Initial plan From 1d68bd0570685e702b387fc1515d27a05a491313 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 26 May 2026 21:00:57 +0000 Subject: [PATCH 2/3] fix: harden redis pool config and avoid double acquire in player_finished --- crates/game_api/src/http/player_finished.rs | 1 - crates/records_lib/src/pool.rs | 37 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/crates/game_api/src/http/player_finished.rs b/crates/game_api/src/http/player_finished.rs index fe58581..11576da 100644 --- a/crates/game_api/src/http/player_finished.rs +++ b/crates/game_api/src/http/player_finished.rs @@ -270,7 +270,6 @@ where .ignore() .zcount(&map_key, "-inf", new - 1); - let mut redis_conn = redis_pool.get().await.with_api_err()?; let (count,): (i32,) = pipe.query_async(&mut redis_conn).await.with_api_err()?; let new_rank = count + 1; diff --git a/crates/records_lib/src/pool.rs b/crates/records_lib/src/pool.rs index e0925b5..d5ed414 100644 --- a/crates/records_lib/src/pool.rs +++ b/crates/records_lib/src/pool.rs @@ -5,6 +5,9 @@ use sea_orm::DbConn; use crate::RedisPool; +const REDIS_POOL_MAX_SIZE: usize = 16; +const REDIS_POOL_WAIT_TIMEOUT_MS: u64 = 2_000; + /// Represents the database of the API, meaning an SQL database, and a Redis database. pub struct Database { /// The SQL database connection pool. This can also be a testing database [`DbConn::MockDatabaseConnection`]. @@ -160,10 +163,36 @@ impl Clone for Database { /// Creates and returns the Redis pool with the provided URL. pub fn get_redis_pool(url: String) -> Result { - let cfg = deadpool_redis::Config { + let cfg = redis_pool_config(url); + cfg.create_pool(Some(Runtime::Tokio1)) +} + +fn redis_pool_config(url: String) -> deadpool_redis::Config { + let mut pool = deadpool_redis::PoolConfig::new(REDIS_POOL_MAX_SIZE); + pool.timeouts = deadpool_redis::Timeouts::wait_millis(REDIS_POOL_WAIT_TIMEOUT_MS); + + deadpool_redis::Config { url: Some(url), connection: None, - pool: None, - }; - cfg.create_pool(Some(Runtime::Tokio1)) + pool: Some(pool), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn redis_pool_uses_fixed_size_and_wait_timeout() { + let cfg = redis_pool_config("redis://127.0.0.1:6379".to_string()); + let pool = cfg.pool.expect("pool config should be set"); + + assert_eq!(pool.max_size, REDIS_POOL_MAX_SIZE); + assert_eq!( + pool.timeouts.wait, + Some(std::time::Duration::from_millis(REDIS_POOL_WAIT_TIMEOUT_MS)) + ); + assert!(pool.timeouts.create.is_none()); + assert!(pool.timeouts.recycle.is_none()); + } } From 2c06e76a2756254b6cc005b7e8302a4c6105acf1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 08:57:10 +0000 Subject: [PATCH 3/3] Reuse existing redis connection in calc_scores --- crates/records_lib/src/mappack.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/records_lib/src/mappack.rs b/crates/records_lib/src/mappack.rs index 525e615..bcb5193 100644 --- a/crates/records_lib/src/mappack.rs +++ b/crates/records_lib/src/mappack.rs @@ -366,8 +366,6 @@ async fn calc_scores( let mut scores = Vec::::with_capacity(mappack.len()); - let mut redis_conn = redis_pool.get().await?; - for (i, map) in mappack.iter().enumerate() { let mut query = Query::select(); query