From b3ce293487583d42471b06c4303e87cdc12645f1 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Sat, 21 Mar 2026 10:30:19 -0300 Subject: [PATCH] fix: Clean up duplicate Redis code and fix WebSocket log level --- src/basic/keywords/add_suggestion.rs | 52 ---------------------------- src/basic/keywords/hearing/talk.rs | 2 +- 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/src/basic/keywords/add_suggestion.rs b/src/basic/keywords/add_suggestion.rs index 76607db6..09c311e9 100644 --- a/src/basic/keywords/add_suggestion.rs +++ b/src/basic/keywords/add_suggestion.rs @@ -10,7 +10,6 @@ use std::time::Duration; static REDIS_CONN: Lazy>> = Lazy::new(|| Mutex::new(None)); fn get_redis_connection(cache_client: &Arc) -> Option { - // Try to reuse existing connection if let Ok(mut guard) = REDIS_CONN.lock() { if let Some(ref mut conn) = *guard { match redis::cmd("PING").query::(conn) { @@ -20,7 +19,6 @@ fn get_redis_connection(cache_client: &Arc) -> Option) -> Option) -> Option { - let timeout = Duration::from_millis(100); - client - .get_connection_with_timeout(timeout) - .ok() - .map(|conn| Self { - conn: Mutex::new(Some(conn)), - }) - } - - fn with_connection(&self, op: F) -> Option - where - F: FnOnce(&mut redis::Connection) -> redis::RedisResult, - { - let mut guard = self.conn.lock().ok()?; - let conn = guard.as_mut()?; - - match op(conn) { - Ok(result) => { - // Connection still valid, put it back - Some(result) - } - Err(_) => { - // Connection failed, try to get a new one - // For simplicity, just return None and caller will retry - *guard = None; - None - } - } - } -} - -fn get_redis_pool(cache_client: &Arc) -> Option> { - static mut POOL: Option> = None; - static mut ONCE: std::sync::Once = std::sync::Once::INIT; - - unsafe { - ONCE.call_once(|| { - POOL = RedisPool::new(cache_client).map(Arc::new); - }); - POOL.clone() - } -} - -fn get_redis_connection(cache_client: &Arc) -> Option { - let timeout = Duration::from_millis(50); - cache_client.get_connection_with_timeout(timeout).ok() -} - #[derive(Debug, Clone)] pub enum SuggestionType { Context(String), diff --git a/src/basic/keywords/hearing/talk.rs b/src/basic/keywords/hearing/talk.rs index c8d74779..236358de 100644 --- a/src/basic/keywords/hearing/talk.rs +++ b/src/basic/keywords/hearing/talk.rs @@ -84,7 +84,7 @@ pub async fn execute_talk( .send_message_to_session(&target_session_id, response_clone) .await { - error!("Failed to send TALK message via web adapter: {}", e); + trace!("No WebSocket connection for session {}: {}", target_session_id, e); } else { trace!("TALK message sent via web adapter to session {}", target_session_id); }