From 8137b6211c9c6701ddd33b684b9376ac112519b6 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Sat, 24 Dec 2022 10:29:47 -0600 Subject: [PATCH] refactor: clippy suggestions --- src/db.rs | 20 ++++++++++---------- src/server.rs | 6 ++++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/db.rs b/src/db.rs index c9e95c1..1b8519b 100644 --- a/src/db.rs +++ b/src/db.rs @@ -102,11 +102,11 @@ pub fn optimize_db(conn: &mut PooledConnection) -> Result<()> { Ok(()) } #[derive(Debug)] -enum SqliteReturnStatus { - SqliteOk, - SqliteBusy, - SqliteError, - SqliteOther(u64), +enum SqliteStatus { + Ok, + Busy, + Error, + Other(u64), } /// Checkpoint/Truncate WAL @@ -120,10 +120,10 @@ pub fn checkpoint_db(conn: &mut PooledConnection) -> Result<()> { Ok((checkpoint_result, wal_size, frames_checkpointed)) })?; let result = match cp_result { - 0 => SqliteReturnStatus::SqliteOk, - 1 => SqliteReturnStatus::SqliteBusy, - 2 => SqliteReturnStatus::SqliteError, - x => SqliteReturnStatus::SqliteOther(x), + 0 => SqliteStatus::Ok, + 1 => SqliteStatus::Busy, + 2 => SqliteStatus::Error, + x => SqliteStatus::Other(x), }; info!( "checkpoint ran in {:?} (result: {:?}, WAL size: {})", @@ -770,7 +770,7 @@ pub async fn db_query( } // logging for slow queries; show sub and SQL. // to reduce logging; only show 1/16th of clients (leading 0) - if row_count == 0 && slow_first_event && client_id.starts_with("0") { + if row_count == 0 && slow_first_event && client_id.starts_with('0') { debug!( "query req (slow): {:?} (cid: {}, sub: {:?})", sub, client_id, sub.id diff --git a/src/server.rs b/src/server.rs index 82894e4..3f89423 100644 --- a/src/server.rs +++ b/src/server.rs @@ -505,8 +505,10 @@ async fn nostr_server( let mut client_published_event_count: usize = 0; let mut client_received_event_count: usize = 0; debug!("new client connection (cid: {}, ip: {:?})", cid, conn.ip()); - let origin = client_info.origin.unwrap_or("".into()); - let user_agent = client_info.user_agent.unwrap_or("".into()); + let origin = client_info.origin.unwrap_or_else(|| "".into()); + let user_agent = client_info + .user_agent + .unwrap_or_else(|| "".into()); debug!( "cid: {}, origin: {:?}, user-agent: {:?}", cid, origin, user_agent