From ba4fcd072a2b071b629ea34eb565e947e04701e1 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Wed, 1 Feb 2023 18:09:30 -0600 Subject: [PATCH] improvement: allow queries to be cancelled earlier (before SQL execution) --- src/repo/sqlite.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/repo/sqlite.rs b/src/repo/sqlite.rs index 6519abe..83c3ace 100644 --- a/src/repo/sqlite.rs +++ b/src/repo/sqlite.rs @@ -344,6 +344,12 @@ impl NostrRepo for SqliteRepo { db_queue_time, client_id, sub.id ); } + // check before getting a DB connection if the client still wants the results + if abandon_query_rx.try_recv().is_ok() { + debug!("query cancelled by client (before execution) (cid: {}, sub: {:?})", client_id, sub.id); + return Ok(()); + } + let start = Instant::now(); let mut row_count: usize = 0; // cutoff for displaying slow queries