From 377d9c32d27d2df37215d0d78acdcbb6d1b65536 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Wed, 6 Sep 2023 16:34:20 +0200 Subject: [PATCH] fix message sending --- src/core/repo/mod.rs | 4 ++-- src/core/room.rs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/repo/mod.rs b/src/core/repo/mod.rs index 4041791..10b601a 100644 --- a/src/core/repo/mod.rs +++ b/src/core/repo/mod.rs @@ -78,7 +78,7 @@ impl Storage { pub async fn insert_message(&mut self, room_id: u32, id: u32, content: &str) -> Result<()> { let mut executor = self.conn.lock().await; - let (_,): (u32,) = sqlx::query_as( + sqlx::query( "insert into messages(room_id, id, content) values (?, ?, ?); update rooms set message_count = message_count + 1 where id = ?;", @@ -87,7 +87,7 @@ impl Storage { .bind(id) .bind(content) .bind(room_id) - .fetch_one(&mut *executor) + .execute(&mut *executor) .await?; Ok(()) diff --git a/src/core/room.rs b/src/core/room.rs index 352c2ea..47826bb 100644 --- a/src/core/room.rs +++ b/src/core/room.rs @@ -140,7 +140,10 @@ impl RoomHandle { pub async fn send_message(&self, player_id: PlayerId, body: Str) { let mut lock = self.0.write().await; - lock.send_message(player_id, body).await; + let res = lock.send_message(player_id, body).await; + if let Err(err) = res { + log::warn!("Failed to send message: {err:?}"); + } } pub async fn get_room_info(&self) -> RoomInfo { @@ -200,6 +203,7 @@ impl Room { } async fn broadcast_update(&self, update: Updates, except: &PlayerId) { + tracing::debug!("Broadcasting an update to {} subs", self.subscriptions.len()); for (player_id, sub) in &self.subscriptions { if player_id == except { continue;