Skip to content

Commit

Permalink
db: add event_id_already_seen method
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Oct 12, 2023
1 parent 0d4199f commit 040cf3b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/nostr-sdk-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pub trait NostrDatabase: AsyncTraitDeps {
/// Save [`Event`] into store
async fn save_event(&self, event: &Event) -> Result<(), Self::Err>;

/// Check if [`EventId`] was already seen
async fn event_id_already_seen(&self, event_id: EventId) -> Result<bool, Self::Err>;

/// Save [`EventId`] seen by relay
///
/// Useful for NIP65 (gossip)
Expand Down
5 changes: 5 additions & 0 deletions crates/nostr-sdk-db/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ impl NostrDatabase for MemoryDatabase {
Ok(())
}

async fn event_id_already_seen(&self, event_id: EventId) -> Result<bool, Self::Err> {
let seen_event_ids = self.seen_event_ids.read().await;
Ok(seen_event_ids.contains_key(&event_id))
}

async fn save_event_id_seen_by_relay(
&self,
event_id: EventId,
Expand Down

0 comments on commit 040cf3b

Please sign in to comment.