Skip to content

Commit

Permalink
pool: dynamic channel size for streaming of events
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
  • Loading branch information
yukibtc committed Nov 1, 2024
1 parent e7ab860 commit 6bfddfa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* pool: deprecate `RelayConnectionStats::uptime` ([Yuki Kishimoto])
* pool: better error for health check if relay status is `Initialized` ([Yuki Kishimoto])
* pool: connect in chunks if too many relays ([Yuki Kishimoto])
* pool: dynamic channel size for streaming of events ([Yuki Kishimoto])
* sdk: deprecate `Client::get_events_of` and `Client::get_events_from` methods ([Yuki Kishimoto])
* sdk: use `Events` instead of `Vec<Event>` in fetch and query methods ([Yuki Kishimoto])
* sdk: rename `stream_events_of` to `stream_events` ([Yuki Kishimoto])
Expand Down
5 changes: 3 additions & 2 deletions crates/nostr-relay-pool/src/pool/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ impl InnerRelayPool {
self.stream_events_targeted(targets, timeout, opts).await
}

// TODO: change target type to `HashMap<Url, Vec<Filter>>`?
pub async fn stream_events_targeted<I, U>(
&self,
targets: I,
Expand All @@ -859,8 +860,6 @@ impl InnerRelayPool {
return Err(Error::NoRelaysSpecified);
}

let (tx, rx) = mpsc::channel::<Event>(4096); // TODO: change to unbounded or allow to change this value?

// Lock with read shared access
let relays = self.relays.read().await;

Expand All @@ -874,6 +873,8 @@ impl InnerRelayPool {
return Err(Error::RelayNotFound);
}

let (tx, rx) = mpsc::channel::<Event>(map.len() * 512);

// Compose events collections
let ids: Arc<Mutex<HashSet<EventId>>> = Arc::new(Mutex::new(HashSet::new()));

Expand Down

0 comments on commit 6bfddfa

Please sign in to comment.