From 075b0bdc47713e303f9954556fa4b4bb472b441a Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Thu, 16 Nov 2023 14:17:03 +0100 Subject: check if already runs and bug fix --- src/services/ping.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/services') diff --git a/src/services/ping.rs b/src/services/ping.rs index 2bff61f..c3bdced 100644 --- a/src/services/ping.rs +++ b/src/services/ping.rs @@ -104,15 +104,13 @@ pub async fn status_websocket(mut socket: WebSocket, state: Arc) { async fn get_eta(db: &PgPool) -> i64 { let query = sqlx::query!( r#"SELECT times FROM devices;"# - ).fetch_optional(db).await.unwrap(); + ).fetch_one(db).await.unwrap(); - match query { - None => { -1 }, - Some(rec) => { - let times = rec.times.unwrap(); - times.iter().sum::() / times.len() as i64 - } - } + let times = match query.times { + None => { vec![0] }, + Some(t) => t, + }; + times.iter().sum::() / times.len() as i64 } -- cgit v1.2.3