diff --git a/src/server.rs b/src/server.rs index f543db7..4b9b4ea 100644 --- a/src/server.rs +++ b/src/server.rs @@ -674,8 +674,10 @@ async fn nostr_server( if let Some(previous_query) = running_queries.insert(s.id.to_owned(), abandon_query_tx) { previous_query.send(()).ok(); } + if s.needs_historical_events() { // start a database query. this spawns a blocking database query on a worker thread. - db::db_query(s, cid.to_owned(), pool.clone(), query_tx.clone(), abandon_query_rx).await; + db::db_query(s, cid.to_owned(), pool.clone(), query_tx.clone(), abandon_query_rx).await; + } }, Err(e) => { info!("Subscription error: {} (cid: {}, sub: {:?})", e, cid, s.id); diff --git a/src/subscription.rs b/src/subscription.rs index 972e978..f019ce2 100644 --- a/src/subscription.rs +++ b/src/subscription.rs @@ -200,6 +200,13 @@ impl Subscription { pub fn get_id(&self) -> String { self.id.clone() } + + /// Determine if any filter is requesting historical (database) + /// queries. If every filter has limit:0, we do not need to query the DB. + pub fn needs_historical_events(&self) -> bool { + self.filters.iter().any(|f| f.limit!=Some(0)) + } + /// Determine if this subscription matches a given [`Event`]. Any /// individual filter match is sufficient. pub fn interested_in_event(&self, event: &Event) -> bool {