improvement: logging failed queries and timing

This commit is contained in:
Greg Heartsfield 2022-01-01 19:25:09 -06:00
parent 3d56262386
commit afc9a0096a
2 changed files with 16 additions and 2 deletions

View File

@ -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()
);
});
}

View File

@ -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)
}
}