Skip to content

Commit

Permalink
sdk: get relay list events also from database in `Client::update_outd…
Browse files Browse the repository at this point in the history
…ated_gossip_graph` method

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Sep 10, 2024
1 parent fb174b8 commit c2232c0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions crates/nostr-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,15 @@ impl Client {
outdated_public_keys: HashSet<PublicKey>,
) -> Result<(), Error> {
if !outdated_public_keys.is_empty() {
// Compose filters
let filter: Filter = Filter::default()
.authors(outdated_public_keys)
.kind(Kind::RelayList);

// Query from database
let database = self.database();
let mut stored_events = database.query(vec![filter.clone()], Order::Desc).await?;

// Get DISCOVERY and READ relays
// TODO: avoid clone of both url and relay
let relays = self
Expand All @@ -1926,14 +1935,14 @@ impl Client {
.await
.into_keys();

// Get events
let filter: Filter = Filter::default()
.authors(outdated_public_keys)
.kind(Kind::RelayList);
let events: Vec<Event> = self
// Get events from discovery and read relays
let mut events: Vec<Event> = self
.get_events_from(relays, vec![filter], Some(Duration::from_secs(10)))
.await?;

// Join database and relays events
events.append(&mut stored_events);

// Update gossip graph
self.gossip_graph.update(events).await;
}
Expand Down

0 comments on commit c2232c0

Please sign in to comment.