fix: use accurate timer for slow queries, and use 250ms as cutoff

This commit is contained in:
Greg Heartsfield 2023-01-31 18:09:43 -06:00
parent 6d57adef73
commit c8e8b71b91

View File

@ -347,7 +347,7 @@ impl NostrRepo for SqliteRepo {
let start = Instant::now(); let start = Instant::now();
let mut row_count: usize = 0; let mut row_count: usize = 0;
// cutoff for displaying slow queries // cutoff for displaying slow queries
let slow_cutoff = Duration::from_millis(1000); let slow_cutoff = Duration::from_millis(250);
let mut filter_count = 0; let mut filter_count = 0;
for filter in sub.filters.iter() { for filter in sub.filters.iter() {
let filter_start = Instant::now(); let filter_start = Instant::now();
@ -448,10 +448,10 @@ impl NostrRepo for SqliteRepo {
warn!("Could not get a database connection for querying"); warn!("Could not get a database connection for querying");
} }
// if the filter took more than 1 second of db_time, print out the JSON. // if the filter took more than 1 second of db_time, print out the JSON.
if start.elapsed() > slow_cutoff && client_id.starts_with('0') { if filter_start.elapsed() > slow_cutoff && client_id.starts_with('0') {
debug!( debug!(
"query filter req (slow): {} (cid: {}, sub: {:?})", "query filter req (slow): {} (cid: {}, sub: {:?}, filter: {})",
serde_json::to_string(&filter)?, client_id, sub.id serde_json::to_string(&filter)?, client_id, sub.id, filter_count
); );
} }