From 8406f414cb560b51f8cc6a550e1da75dc0271e98 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Fri, 29 Nov 2024 08:52:19 +0100 Subject: [PATCH] ndb: bump `nostr-ndb` to 0.4 Fixes https://github.com/rust-nostr/nostr/issues/454 Signed-off-by: Yuki Kishimoto --- CHANGELOG.md | 3 ++- Cargo.lock | 4 ++-- .../nostr-sdk-ffi/python/examples/database.py | 4 ---- crates/nostr-ndb/Cargo.toml | 2 +- crates/nostr-ndb/src/lib.rs | 21 +++++++++---------- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5039bea4e..09fa85f33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,9 +33,10 @@ ### Changed -* Bump `async-utility` to 0.3 and `async-wsocket` to 0.11 ([Yuki Kishimoto]) +* Bump `async-utility` to 0.3, `async-wsocket` to 0.11 and `atomic-destructor` to 0.3 ([Yuki Kishimoto]) * nostr: remove self-tagging when building events ([Yuki Kishimoto]) * lmdb: use `async-utility` to spawn blocking tasks ([Yuki Kishimoto]) +* ndb: bump `nostr-ndb` to 0.4 ([Yuki Kishimoto]) * pool: add `PingTracker` and improve relay ping management ([Yuki Kishimoto]) ### Added diff --git a/Cargo.lock b/Cargo.lock index 8249f25c6..6f80abf34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3352,9 +3352,9 @@ dependencies = [ [[package]] name = "nostrdb" -version = "0.3.4" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39d273f35f529a06f967c0115edd03d62b686a50bd13fa850ce1293f0a02877d" +checksum = "aec87d9a1d4252ddb03539823f46df2357ca4f793f88e364b4bee382d7bfed80" dependencies = [ "bindgen", "cc", diff --git a/bindings/nostr-sdk-ffi/python/examples/database.py b/bindings/nostr-sdk-ffi/python/examples/database.py index 2baa2bd5e..1ea59d376 100644 --- a/bindings/nostr-sdk-ffi/python/examples/database.py +++ b/bindings/nostr-sdk-ffi/python/examples/database.py @@ -11,10 +11,6 @@ async def main(): # Create/open LMDB database database = NostrDatabase.lmdb("nostr-lmdb") - # NOT AVAILABLE ON WINDOWS AT THE MOMENT! - # Create/open nostrdb database - # database = NostrDatabase.ndb("ndb") - client = ClientBuilder().database(database).build() await client.add_relay("wss://relay.damus.io") diff --git a/crates/nostr-ndb/Cargo.toml b/crates/nostr-ndb/Cargo.toml index e48d322be..455d07f10 100644 --- a/crates/nostr-ndb/Cargo.toml +++ b/crates/nostr-ndb/Cargo.toml @@ -15,5 +15,5 @@ keywords = ["nostr", "database", "ndb", "nostrdb"] async-trait.workspace = true nostr = { workspace = true, features = ["std"] } nostr-database.workspace = true -nostrdb = "0.3" +nostrdb = "0.4" tracing = { workspace = true, features = ["std", "attributes"] } diff --git a/crates/nostr-ndb/src/lib.rs b/crates/nostr-ndb/src/lib.rs index 6ab4a5d8b..ecee7581d 100644 --- a/crates/nostr-ndb/src/lib.rs +++ b/crates/nostr-ndb/src/lib.rs @@ -49,9 +49,10 @@ impl NdbDatabase { txn: &'a Transaction, filters: Vec, ) -> Result>, DatabaseError> { - let filters = filters.into_iter().map(ndb_filter_conversion).collect(); + let filters: Vec = + filters.into_iter().map(ndb_filter_conversion).collect(); self.db - .query(txn, filters, MAX_RESULTS) + .query(txn, &filters, MAX_RESULTS) .map_err(DatabaseError::backend) } } @@ -184,41 +185,39 @@ fn ndb_filter_conversion(f: Filter) -> nostrdb::Filter { if let Some(ids) = f.ids { if !ids.is_empty() { - let ids: Vec<[u8; 32]> = ids.into_iter().map(|p| p.to_bytes()).collect(); - filter.ids(ids); + filter = filter.ids(ids.iter().map(|p| p.as_bytes())); } } if let Some(authors) = f.authors { if !authors.is_empty() { let authors: Vec<[u8; 32]> = authors.into_iter().map(|p| p.serialize()).collect(); - filter.authors(authors); + filter = filter.authors(authors.iter()); } } if let Some(kinds) = f.kinds { if !kinds.is_empty() { - let kinds: Vec = kinds.into_iter().map(|p| p.as_u16() as u64).collect(); - filter.kinds(kinds); + filter = filter.kinds(kinds.into_iter().map(|p| p.as_u16() as u64)); } } if !f.generic_tags.is_empty() { for (single_letter, set) in f.generic_tags.into_iter() { - filter.tags(set.into_iter().collect(), single_letter.as_char()); + filter = filter.tags(set, single_letter.as_char()); } } if let Some(since) = f.since { - filter.since(since.as_u64()); + filter = filter.since(since.as_u64()); } if let Some(until) = f.until { - filter.until(until.as_u64()); + filter = filter.until(until.as_u64()); } if let Some(limit) = f.limit { - filter.limit(limit as u64); + filter = filter.limit(limit as u64); } filter.build()