diff --git a/src/conn.rs b/src/conn.rs index ed6e177..71b366d 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -2,7 +2,6 @@ use crate::close::Close; use crate::error::Error; use crate::error::Result; -use crate::event::Event; use crate::subscription::Subscription; use std::collections::HashMap; @@ -43,6 +42,10 @@ impl ClientConn { } } + pub fn subscriptions(&self) -> &HashMap { + &self.subscriptions + } + /// Get a short prefix of the client's unique identifier, suitable /// for logging. #[must_use] @@ -55,18 +58,6 @@ impl ClientConn { &self.client_ip } - /// Find all matching subscriptions. - #[must_use] - pub fn get_matching_subscriptions(&self, e: &Event) -> Vec<&str> { - let mut v: Vec<&str> = vec![]; - for (id, sub) in &self.subscriptions { - if sub.interested_in_event(e) { - v.push(id); - } - } - v - } - /// Add a new subscription for this connection. /// # Errors /// diff --git a/src/server.rs b/src/server.rs index 8cda8ec..c50b00a 100644 --- a/src/server.rs +++ b/src/server.rs @@ -499,8 +499,11 @@ async fn nostr_server( Ok(global_event) = bcast_rx.recv() => { // an event has been broadcast to all clients // first check if there is a subscription for this event. - let matching_subs = conn.get_matching_subscriptions(&global_event); - for s in matching_subs { + for (s, sub) in conn.subscriptions() { + if !sub.interested_in_event(&global_event) { + continue; + } + // TODO: serialize at broadcast time, instead of // once for each consumer. if let Ok(event_str) = serde_json::to_string(&global_event) {