nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

commit afc9a0096a17e31be27d7623397e70b192c1d2cf
parent 3d5626238674cb1ced2e7e84507dae7d4fcdcf0d
Author: Greg Heartsfield <scsibug@imap.cc>
Date:   Sat,  1 Jan 2022 19:25:09 -0600

improvement: logging failed queries and timing

Diffstat:
Msrc/db.rs | 17+++++++++++++++--
Msrc/protostream.rs | 1+
2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/db.rs b/src/db.rs @@ -13,6 +13,7 @@ use rusqlite::OpenFlags; use crate::config::SETTINGS; use std::path::Path; use std::thread; +use std::time::Instant; use tokio::task; /// Database file @@ -157,12 +158,17 @@ pub async fn db_writer( } let mut event_write = false; let event = next_event.unwrap(); + let start = Instant::now(); match write_event(&mut conn, &event) { Ok(updated) => { if updated == 0 { debug!("ignoring duplicate event"); } else { - info!("persisted event: {}", event.get_event_id_prefix()); + info!( + "persisted event: {} in {:?}", + event.get_event_id_prefix(), + start.elapsed() + ); event_write = true; // send this out to all clients bcast_tx.send(event.clone()).ok(); @@ -402,6 +408,8 @@ pub async fn db_query( Connection::open_with_flags(&full_path, OpenFlags::SQLITE_OPEN_READ_ONLY).unwrap(); debug!("opened database for reading"); debug!("going to query for: {:?}", sub); + let mut row_count: usize = 0; + let start = Instant::now(); // generate SQL query let q = query_from_sub(&sub); // execute the query @@ -413,6 +421,7 @@ pub async fn db_query( debug!("query aborted"); return; } + row_count += 1; // TODO: check before unwrapping let event_json = row.get(0).unwrap(); query_tx @@ -422,6 +431,10 @@ pub async fn db_query( }) .ok(); } - debug!("query completed"); + debug!( + "query completed ({} rows) in {:?}", + row_count, + start.elapsed() + ); }); } diff --git a/src/protostream.rs b/src/protostream.rs @@ -71,6 +71,7 @@ impl Stream for NostrStream { } Err(e) => { debug!("proto parse error: {:?}", e); + debug!("parse error on message: {}", msg.trim()); Err(Error::ProtoParseError) } }