From d630790b0763f3a0d11b316bac6dca6903f1c62c Mon Sep 17 00:00:00 2001 From: xy Date: Mon, 18 Nov 2024 03:14:52 +0900 Subject: [PATCH] perf(relay): optimize relay connection handling --- crates/nostr-connect/src/signer.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/nostr-connect/src/signer.rs b/crates/nostr-connect/src/signer.rs index f672ae2ba..e886b421c 100644 --- a/crates/nostr-connect/src/signer.rs +++ b/crates/nostr-connect/src/signer.rs @@ -6,6 +6,7 @@ use std::time::Duration; +use async_utility::futures_util::future::try_join_all; use nostr::nips::nip46::{Message, Request, ResponseResult}; use nostr_relay_pool::prelude::*; @@ -36,13 +37,14 @@ impl NostrConnectRemoteSigner { U: TryIntoUrl, pool::Error: From<::Err>, { - // Compose pool let pool: RelayPool = RelayPool::default(); - let opts: RelayOptions = opts.unwrap_or_default(); - for url in relays.into_iter() { - pool.add_relay(url, opts.clone()).await?; - } + + let futures: Vec<_> = relays + .into_iter() + .map(|url| pool.add_relay(url, opts.clone())) + .collect(); + try_join_all(futures).await?; pool.connect(Some(Duration::from_secs(10))).await;