From a2217a991c1923ab447a10934b41221d9271f922 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 5 Mar 2026 11:13:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84ConnectionManager=EF=BC=9A?= =?UTF-8?q?=E7=AE=80=E5=8C=96get=5Fsession=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4pool=E4=BE=9D=E8=B5=96=EF=BC=8C=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8Dnew=5Fwith=5Fpool=E4=B8=BAnew?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/connection.rs | 29 ++++++----------------------- src/main.rs | 2 +- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/src/connection.rs b/src/connection.rs index bf53e3d..486e6ef 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -105,7 +105,6 @@ pub struct ConnectionManager { point_monitor_data: Arc>>, point_history_data: Arc>>>, point_write_target_cache: Arc>>, - pool: Option, event_manager: Option>, } @@ -155,10 +154,9 @@ impl ConnectionManager { } } - pub fn new_with_pool(pool: sqlx::PgPool) -> Self { + pub fn new() -> Self { Self { status: Arc::new(RwLock::new(HashMap::new())), - pool: Some(pool), point_monitor_data: Arc::new(RwLock::new(HashMap::new())), point_history_data: Arc::new(RwLock::new(HashMap::new())), point_write_target_cache: Arc::new(RwLock::new(HashMap::new())), @@ -562,28 +560,13 @@ impl ConnectionManager { } pub async fn get_session(&self, source_id: Uuid) -> Option> { - // comment fixed - { - let status = self.status.read().await; - if let Some(conn_status) = status.get(&source_id) { - if conn_status.is_connected { - return conn_status.session.clone(); - } + let status = self.status.read().await; + if let Some(conn_status) = status.get(&source_id) { + if conn_status.is_connected { + return conn_status.session.clone(); } } - - // comment fixed - if let Some(pool) = &self.pool { - if let Ok(()) = self.connect_from_source(pool, source_id).await { - // comment fixed - let status = self.status.read().await; - status.get(&source_id).and_then(|s| s.session.clone()) - } else { - None - } - } else { - None - } + None } pub async fn get_status(&self, source_id: Uuid) -> Option { diff --git a/src/main.rs b/src/main.rs index 79c9f63..2271e63 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ async fn main() { let config = AppConfig::from_env().expect("Failed to load configuration"); let pool = init_database(&config.database_url).await.expect("Failed to initialize database"); - let mut connection_manager = ConnectionManager::new_with_pool(pool.clone()); + let mut connection_manager = ConnectionManager::new(); let ws_manager = Arc::new(websocket::WebSocketManager::new()); let event_manager = Arc::new(EventManager::new( pool.clone(),