chore: connect to search relays only when needed

This commit is contained in:
2026-06-01 15:07:11 +07:00
parent 2e451aae12
commit 4efeec08c4
2 changed files with 27 additions and 23 deletions

View File

@@ -220,14 +220,6 @@ impl NostrRegistry {
let client = self.client();
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
// Add search relay to the relay pool
for url in SEARCH_RELAYS.into_iter() {
client
.add_relay(url)
.capabilities(RelayCapabilities::READ)
.await?;
}
// Add indexer relay to the relay pool
for url in INDEXER_RELAYS.into_iter() {
client
@@ -633,6 +625,18 @@ impl NostrRegistry {
return Ok(results);
}
// Add search relay to the relay pool
for url in SEARCH_RELAYS.into_iter() {
if client.relay(url).await.is_ok() {
client
.add_relay(url)
.capabilities(RelayCapabilities::READ)
.await?;
} else {
return Err(anyhow!("Failed to add search relay: {}", url));
}
}
// Return early if the query is a valid public key
if let Ok(public_key) = PublicKey::parse(&query) {
results.push(public_key);