diff --git a/CHANGELOG.md b/CHANGELOG.md index a2a87a75e..b32cab6f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ * pool: remove IDs collection from `InternalRelayPool::get_events_from` ([Yuki Kishimoto]) * pool: better checks before perform queries or send messages to relays ([Yuki Kishimoto]) * pool: bump `async-wsocket` to `v0.6` ([Yuki Kishimoto]) +* pool: get events only from remote relay when calling `get_events_of` or `get_events_from` ([Yuki Kishimoto]) * database: not match event if `Filter::search` field is set ([Yuki Kishimoto]) * database: avoid to copy `EventId` in `Event::decode` ([Yuki Kishimoto]) * database: use `Vec` instead of `BTreeSet` as inner value for `TagIndexValues` ([Yuki Kishimoto]) diff --git a/bindings/nostr-sdk-ffi/src/client/mod.rs b/bindings/nostr-sdk-ffi/src/client/mod.rs index 532141eef..f620b90ed 100644 --- a/bindings/nostr-sdk-ffi/src/client/mod.rs +++ b/bindings/nostr-sdk-ffi/src/client/mod.rs @@ -373,8 +373,6 @@ impl Client { } /// Get events of filters from specific relays - /// - /// Get events both from **local database** and **relays** pub async fn get_events_from( &self, urls: Vec, diff --git a/bindings/nostr-sdk-ffi/src/pool/mod.rs b/bindings/nostr-sdk-ffi/src/pool/mod.rs index c160c87de..e99ff9fe7 100644 --- a/bindings/nostr-sdk-ffi/src/pool/mod.rs +++ b/bindings/nostr-sdk-ffi/src/pool/mod.rs @@ -353,8 +353,6 @@ impl RelayPool { } /// Get events of filters - /// - /// Get events both from **local database** and **relays** pub async fn get_events_of( &self, filters: Vec>, @@ -375,8 +373,6 @@ impl RelayPool { } /// Get events of filters from **specific relays** - /// - /// Get events both from **local database** and **relays** pub async fn get_events_from( &self, urls: Vec, diff --git a/bindings/nostr-sdk-ffi/src/relay/mod.rs b/bindings/nostr-sdk-ffi/src/relay/mod.rs index 2ccbbd342..0b44e3a23 100644 --- a/bindings/nostr-sdk-ffi/src/relay/mod.rs +++ b/bindings/nostr-sdk-ffi/src/relay/mod.rs @@ -333,8 +333,6 @@ impl Relay { } /// Get events of filters - /// - /// Get events from local database and relay pub async fn get_events_of( &self, filters: Vec>, diff --git a/bindings/nostr-sdk-js/src/client/mod.rs b/bindings/nostr-sdk-js/src/client/mod.rs index e24657c20..c04ef6840 100644 --- a/bindings/nostr-sdk-js/src/client/mod.rs +++ b/bindings/nostr-sdk-js/src/client/mod.rs @@ -361,8 +361,6 @@ impl JsClient { } /// Get events of filters from specific relays - /// - /// Get events both from **local database** and **relays** #[wasm_bindgen(js_name = getEventsFrom)] pub async fn get_events_from( &self, diff --git a/bindings/nostr-sdk-js/src/pool/mod.rs b/bindings/nostr-sdk-js/src/pool/mod.rs index d1c0be4a9..9425a3e43 100644 --- a/bindings/nostr-sdk-js/src/pool/mod.rs +++ b/bindings/nostr-sdk-js/src/pool/mod.rs @@ -387,8 +387,6 @@ impl JsRelayPool { } // /// Get events of filters - // /// - // /// Get events both from **local database** and **relays** // #[wasm_bindgen(js_name = getEventsOf)] // pub async fn get_events_of( // &self, @@ -410,8 +408,6 @@ impl JsRelayPool { // } // // /// Get events of filters from **specific relays** - // /// - // /// Get events both from **local database** and **relays** // #[wasm_bindgen(js_name = getEventsFrom)] // pub async fn get_events_from( // &self, diff --git a/bindings/nostr-sdk-js/src/relay/mod.rs b/bindings/nostr-sdk-js/src/relay/mod.rs index 5ccc9cde5..904eea5c8 100644 --- a/bindings/nostr-sdk-js/src/relay/mod.rs +++ b/bindings/nostr-sdk-js/src/relay/mod.rs @@ -262,8 +262,6 @@ impl JsRelay { } /// Get events of filters - /// - /// Get events from local database and relay #[wasm_bindgen(js_name = getEventsOf)] pub async fn get_events_of( &self, diff --git a/crates/nostr-relay-pool/src/pool/internal.rs b/crates/nostr-relay-pool/src/pool/internal.rs index 898795d69..6ac452ef7 100644 --- a/crates/nostr-relay-pool/src/pool/internal.rs +++ b/crates/nostr-relay-pool/src/pool/internal.rs @@ -14,7 +14,7 @@ use async_utility::thread::JoinHandle; use async_utility::{thread, time}; use atomic_destructor::AtomicDestroyer; use nostr::{ClientMessage, Event, EventId, Filter, SubscriptionId, Timestamp, TryIntoUrl, Url}; -use nostr_database::{DynNostrDatabase, IntoNostrDatabase, Order}; +use nostr_database::{DynNostrDatabase, IntoNostrDatabase}; use tokio::sync::{broadcast, mpsc, Mutex, RwLock}; use tokio_stream::wrappers::ReceiverStream; @@ -632,15 +632,8 @@ impl InternalRelayPool { return Err(Error::RelayNotFound); } - let stored_events: Vec = self - .database - .query(filters.clone(), Order::Desc) - .await - .unwrap_or_default(); - // Compose events collections - let events: Arc>> = - Arc::new(Mutex::new(stored_events.into_iter().collect())); + let events: Arc>> = Arc::new(Mutex::new(BTreeSet::new())); // Filter relays and start query let mut handles = Vec::with_capacity(urls.len()); diff --git a/crates/nostr-relay-pool/src/pool/mod.rs b/crates/nostr-relay-pool/src/pool/mod.rs index f93c779e7..732b7490c 100644 --- a/crates/nostr-relay-pool/src/pool/mod.rs +++ b/crates/nostr-relay-pool/src/pool/mod.rs @@ -423,8 +423,6 @@ impl RelayPool { } /// Get events of filters - /// - /// Get events both from **local database** and **relays** #[inline] pub async fn get_events_of( &self, @@ -438,8 +436,6 @@ impl RelayPool { } /// Get events of filters from **specific relays** - /// - /// Get events both from **local database** and **relays** #[inline] pub async fn get_events_from( &self, diff --git a/crates/nostr-relay-pool/src/relay/internal.rs b/crates/nostr-relay-pool/src/relay/internal.rs index 4708b3c04..d3c84c50d 100644 --- a/crates/nostr-relay-pool/src/relay/internal.rs +++ b/crates/nostr-relay-pool/src/relay/internal.rs @@ -5,7 +5,7 @@ //! Internal Relay use std::cmp; -use std::collections::{BTreeSet, HashMap, HashSet}; +use std::collections::{HashMap, HashSet}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::time::Duration; @@ -24,7 +24,7 @@ use nostr::{ ClientMessage, Event, EventId, Filter, JsonUtil, Keys, Kind, MissingPartialEvent, PartialEvent, RawRelayMessage, RelayMessage, SubscriptionId, Timestamp, Url, }; -use nostr_database::{DynNostrDatabase, Order}; +use nostr_database::DynNostrDatabase; use tokio::sync::mpsc::{self, Receiver, Sender}; use tokio::sync::{broadcast, oneshot, watch, Mutex, MutexGuard, RwLock}; @@ -1603,18 +1603,13 @@ impl InternalRelay { timeout: Duration, opts: FilterOptions, ) -> Result, Error> { - let stored_events: Vec = self - .database - .query(filters.clone(), Order::Desc) - .await - .unwrap_or_default(); - let events: Mutex> = Mutex::new(stored_events.into_iter().collect()); + let events: Mutex> = Mutex::new(Vec::new()); self.get_events_of_with_callback(filters, timeout, opts, |event| async { let mut events = events.lock().await; - events.insert(event); + events.push(event); }) .await?; - Ok(events.into_inner().into_iter().rev().collect()) + Ok(events.into_inner()) } pub async fn count_events_of( diff --git a/crates/nostr-relay-pool/src/relay/mod.rs b/crates/nostr-relay-pool/src/relay/mod.rs index 0ef63b367..ad9774772 100644 --- a/crates/nostr-relay-pool/src/relay/mod.rs +++ b/crates/nostr-relay-pool/src/relay/mod.rs @@ -377,8 +377,6 @@ impl Relay { } /// Get events of filters - /// - /// Get events from local database and relay #[inline] pub async fn get_events_of( &self, diff --git a/crates/nostr-sdk/src/client/mod.rs b/crates/nostr-sdk/src/client/mod.rs index 2047c852d..377c8a6f6 100644 --- a/crates/nostr-sdk/src/client/mod.rs +++ b/crates/nostr-sdk/src/client/mod.rs @@ -859,8 +859,6 @@ impl Client { } /// Get events of filters from specific relays - /// - /// Get events both from **local database** and **relays** #[inline] pub async fn get_events_from( &self,