From 5979e13cdc65ea78894dbcab3acde11b246889a7 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 28 Oct 2024 15:05:38 +0000 Subject: refactor: replace sqlite with lmdb as sqlite is depricated in rust-nostr --- Cargo.lock | 210 +++++++++++++++++++++++++++++++++++--------------- Cargo.toml | 2 +- src/lib/client.rs | 22 +++--- test_utils/Cargo.toml | 2 +- test_utils/src/lib.rs | 11 ++- 5 files changed, 165 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 503a164..f5c0227 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -499,6 +499,9 @@ name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +dependencies = [ + "serde", +] [[package]] name = "block-buffer" @@ -720,6 +723,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-queue" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" @@ -838,6 +850,15 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" +[[package]] +name = "doxygen-rs" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "415b6ec780d34dcf624666747194393603d0373b7141eef01d12ee58881507d9" +dependencies = [ + "phf", +] + [[package]] name = "duplicate" version = "1.0.0" @@ -935,18 +956,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "fallible-iterator" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" - -[[package]] -name = "fallible-streaming-iterator" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" - [[package]] name = "fastrand" version = "1.9.0" @@ -1204,15 +1213,6 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" -[[package]] -name = "hashlink" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" -dependencies = [ - "hashbrown 0.14.5", -] - [[package]] name = "heck" version = "0.4.1" @@ -1225,6 +1225,40 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "heed" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d4f449bab7320c56003d37732a917e18798e2f1709d80263face2b4f9436ddb" +dependencies = [ + "bitflags 2.6.0", + "byteorder", + "heed-traits", + "heed-types", + "libc", + "lmdb-master-sys", + "once_cell", + "page_size", + "synchronoise", + "url", +] + +[[package]] +name = "heed-traits" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3130048d404c57ce5a1ac61a903696e8fcde7e8c2991e9fcfc1f27c3ef74ff" + +[[package]] +name = "heed-types" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d3f528b053a6d700b2734eabcd0fd49cb8230647aa72958467527b0b7917114" +dependencies = [ + "byteorder", + "heed-traits", +] + [[package]] name = "hermit-abi" version = "0.3.9" @@ -1544,17 +1578,6 @@ dependencies = [ "libc", ] -[[package]] -name = "libsqlite3-sys" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c10584274047cb335c23d3e61bcef8e323adae7c5c8c760540f73610177fc3f" -dependencies = [ - "cc", - "pkg-config", - "vcpkg", -] - [[package]] name = "libssh2-sys" version = "0.3.0" @@ -1603,6 +1626,17 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "lmdb-master-sys" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "472c3760e2a8d0f61f322fb36788021bb36d573c502b50fa3e2bcaac3ec326c9" +dependencies = [ + "cc", + "doxygen-rs", + "libc", +] + [[package]] name = "lnurl-pay" version = "0.6.0" @@ -1760,9 +1794,9 @@ dependencies = [ "mockall", "nostr", "nostr-database", + "nostr-lmdb", "nostr-sdk", "nostr-signer", - "nostr-sqlite", "once_cell", "passwords", "qrcode", @@ -1850,6 +1884,19 @@ dependencies = [ "tracing", ] +[[package]] +name = "nostr-lmdb" +version = "0.35.0" +source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" +dependencies = [ + "heed", + "nostr", + "nostr-database", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "nostr-relay-pool" version = "0.35.0" @@ -1900,20 +1947,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "nostr-sqlite" -version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=4dbfa94#4dbfa94876b136869e2feea75288f0c6a0beaa0e" -dependencies = [ - "async-trait", - "nostr", - "nostr-database", - "rusqlite", - "thiserror", - "tokio", - "tracing", -] - [[package]] name = "nostr-zapper" version = "0.35.0" @@ -2074,6 +2107,16 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "page_size" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "parking" version = "2.2.1" @@ -2139,6 +2182,48 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "phf" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" +dependencies = [ + "phf_macros", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro2", + "quote", + "syn 2.0.79", +] + +[[package]] +name = "phf_shared" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" +dependencies = [ + "siphasher", +] + [[package]] name = "pin-project" version = "1.1.5" @@ -2578,20 +2663,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rusqlite" -version = "0.31.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b838eba278d213a8beaf485bd313fd580ca4505a00d5871caeb1457c55322cae" -dependencies = [ - "bitflags 2.6.0", - "fallible-iterator", - "fallible-streaming-iterator", - "hashlink", - "libsqlite3-sys", - "smallvec", -] - [[package]] name = "rustc-demangle" version = "0.1.24" @@ -2930,6 +3001,12 @@ dependencies = [ "tokio-tungstenite 0.20.1", ] +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + [[package]] name = "slab" version = "0.4.9" @@ -3032,6 +3109,15 @@ dependencies = [ "futures-core", ] +[[package]] +name = "synchronoise" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dbc01390fc626ce8d1cffe3376ded2b72a11bb70e1c75f404a210e4daa4def2" +dependencies = [ + "crossbeam-queue", +] + [[package]] name = "tempfile" version = "3.13.0" @@ -3073,8 +3159,8 @@ dependencies = [ "git2", "nostr", "nostr-database", + "nostr-lmdb", "nostr-sdk", - "nostr-sqlite", "once_cell", "rand", "rexpect", diff --git a/Cargo.toml b/Cargo.toml index fccd2b1..79a9990 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ nostr = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } nostr-signer = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } -nostr-sqlite = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } +nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } passwords = "3.1.13" qrcode = { version = "0.14.1", default-features = false } scrypt = "0.11.0" diff --git a/src/lib/client.rs b/src/lib/client.rs index 5f9e996..8a381ab 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs @@ -30,11 +30,11 @@ use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressState, P use mockall::*; use nostr::{nips::nip01::Coordinate, Event}; use nostr_database::NostrDatabase; +use nostr_lmdb::NostrLMDB; use nostr_sdk::{ prelude::RelayLimits, EventBuilder, EventId, Kind, NostrSigner, Options, PublicKey, SingleLetterTag, Timestamp, Url, }; -use nostr_sqlite::SQLiteDatabase; use crate::{ get_dirs, @@ -157,7 +157,7 @@ impl Connect for Client { .opts(Options::new().relay_limits(RelayLimits::disable())) .signer(opts.keys.unwrap_or(nostr::Keys::generate())) // .database( - // SQLiteDatabase::open(get_dirs()?.cache_dir().join("nostr-cache.sqlite")). + // SQLiteDatabase::open(get_dirs()?.cache_dir().join("nostr-cache.lmdb")). // await?, ) .build(), fallback_relays: opts.fallback_relays, @@ -732,23 +732,21 @@ fn pb_after_style(succeed: bool) -> indicatif::ProgressStyle { .unwrap() } -async fn get_local_cache_database(git_repo_path: &Path) -> Result { - SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite")) - .await - .context("cannot open or create nostr cache database at .git/nostr-cache.sqlite") +async fn get_local_cache_database(git_repo_path: &Path) -> Result { + NostrLMDB::open(git_repo_path.join(".git/nostr-cache.lmdb")) + .context("cannot open or create nostr cache database at .git/nostr-cache.lmdb") } -async fn get_global_cache_database(git_repo_path: &Path) -> Result { - SQLiteDatabase::open(if std::env::var("NGITTEST").is_err() { +async fn get_global_cache_database(git_repo_path: &Path) -> Result { + NostrLMDB::open(if std::env::var("NGITTEST").is_err() { create_dir_all(get_dirs()?.cache_dir()).context(format!( "cannot create cache directory in: {:?}", get_dirs()?.cache_dir() ))?; - get_dirs()?.cache_dir().join("nostr-cache.sqlite") + get_dirs()?.cache_dir().join("nostr-cache.lmdb") } else { - git_repo_path.join(".git/test-global-cache.sqlite") + git_repo_path.join(".git/test-global-cache.lmdb") }) - .await .context("cannot open ngit global nostr cache database") } @@ -761,7 +759,7 @@ pub async fn get_events_from_cache( .query(filters.clone()) .await .context( - "cannot execute query on opened git repo nostr cache database .git/nostr-cache.sqlite", + "cannot execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", ) } diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index 68484cb..403e478 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml @@ -13,7 +13,7 @@ git2 = "0.19.0" nostr = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } -nostr-sqlite = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } +nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "4dbfa94" } once_cell = "1.18.0" rand = "0.8" rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index f329681..57b0643 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -11,8 +11,8 @@ use futures::executor::block_on; use git::GitTestRepo; use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; use nostr_database::NostrDatabase; +use nostr_lmdb::NostrLMDB; use nostr_sdk::{serde_json, Client, NostrSigner, TagStandard}; -use nostr_sqlite::SQLiteDatabase; use once_cell::sync::Lazy; use rexpect::session::{Options, PtySession}; use strip_ansi_escapes::strip_str; @@ -1051,10 +1051,9 @@ where } /** copied from client.rs */ -async fn get_local_cache_database(git_repo_path: &Path) -> Result { - SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite")) - .await - .context("cannot open or create nostr cache database at .git/nostr-cache.sqlite") +async fn get_local_cache_database(git_repo_path: &Path) -> Result { + NostrLMDB::open(git_repo_path.join(".git/nostr-cache.lmdb")) + .context("cannot open or create nostr cache database at .git/nostr-cache.lmdb") } /** copied from client.rs */ @@ -1067,7 +1066,7 @@ pub async fn get_events_from_cache( .query(filters.clone()) .await .context( - "cannot execute query on opened git repo nostr cache database .git/nostr-cache.sqlite", + "cannot execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", ) } -- cgit v1.2.3