From 5c202fae4dfdfb36c7fb29da269f94e92904ffee Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sat, 23 Dec 2023 18:47:39 -0800 Subject: [PATCH] relays: only give up looking when it makes sense --- src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index ba215a9..f31c22c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,11 +52,14 @@ pub async fn find_note(app: &Notecrumbs, nip19: &Nip19) -> Result Result = None; let mut profile: Option = None; + let mut ends: i32 = 0; loop { match client.notifications().recv().await? { @@ -88,7 +92,13 @@ pub async fn find_note(app: &Notecrumbs, nip19: &Nip19) -> Result return Ok(FindNoteResult { note, profile }), + RelayMessage::EndOfStoredEvents(_) => { + ends += 1; + let has_any = note.is_some() || profile.is_some(); + if has_any || ends >= num_relays { + return Ok(FindNoteResult { note, profile }); + } + } _ => continue, }, RelayPoolNotification::Stop | RelayPoolNotification::Shutdown => {