diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-10-28 15:05:38 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-10-28 15:05:38 +0000 |
| commit | 5979e13cdc65ea78894dbcab3acde11b246889a7 (patch) | |
| tree | 9dfb0971847bfa3a5a064f39e01bd0415fd05946 /src | |
| parent | e60a419510696e3fa25a35be6cba35e547b53e24 (diff) | |
refactor: replace sqlite with lmdb
as sqlite is depricated in rust-nostr
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/client.rs | 22 |
1 files changed, 10 insertions, 12 deletions
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 | |||
| 30 | use mockall::*; | 30 | use mockall::*; |
| 31 | use nostr::{nips::nip01::Coordinate, Event}; | 31 | use nostr::{nips::nip01::Coordinate, Event}; |
| 32 | use nostr_database::NostrDatabase; | 32 | use nostr_database::NostrDatabase; |
| 33 | use nostr_lmdb::NostrLMDB; | ||
| 33 | use nostr_sdk::{ | 34 | use nostr_sdk::{ |
| 34 | prelude::RelayLimits, EventBuilder, EventId, Kind, NostrSigner, Options, PublicKey, | 35 | prelude::RelayLimits, EventBuilder, EventId, Kind, NostrSigner, Options, PublicKey, |
| 35 | SingleLetterTag, Timestamp, Url, | 36 | SingleLetterTag, Timestamp, Url, |
| 36 | }; | 37 | }; |
| 37 | use nostr_sqlite::SQLiteDatabase; | ||
| 38 | 38 | ||
| 39 | use crate::{ | 39 | use crate::{ |
| 40 | get_dirs, | 40 | get_dirs, |
| @@ -157,7 +157,7 @@ impl Connect for Client { | |||
| 157 | .opts(Options::new().relay_limits(RelayLimits::disable())) | 157 | .opts(Options::new().relay_limits(RelayLimits::disable())) |
| 158 | .signer(opts.keys.unwrap_or(nostr::Keys::generate())) | 158 | .signer(opts.keys.unwrap_or(nostr::Keys::generate())) |
| 159 | // .database( | 159 | // .database( |
| 160 | // SQLiteDatabase::open(get_dirs()?.cache_dir().join("nostr-cache.sqlite")). | 160 | // SQLiteDatabase::open(get_dirs()?.cache_dir().join("nostr-cache.lmdb")). |
| 161 | // await?, ) | 161 | // await?, ) |
| 162 | .build(), | 162 | .build(), |
| 163 | fallback_relays: opts.fallback_relays, | 163 | fallback_relays: opts.fallback_relays, |
| @@ -732,23 +732,21 @@ fn pb_after_style(succeed: bool) -> indicatif::ProgressStyle { | |||
| 732 | .unwrap() | 732 | .unwrap() |
| 733 | } | 733 | } |
| 734 | 734 | ||
| 735 | async fn get_local_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabase> { | 735 | async fn get_local_cache_database(git_repo_path: &Path) -> Result<NostrLMDB> { |
| 736 | SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite")) | 736 | NostrLMDB::open(git_repo_path.join(".git/nostr-cache.lmdb")) |
| 737 | .await | 737 | .context("cannot open or create nostr cache database at .git/nostr-cache.lmdb") |
| 738 | .context("cannot open or create nostr cache database at .git/nostr-cache.sqlite") | ||
| 739 | } | 738 | } |
| 740 | 739 | ||
| 741 | async fn get_global_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabase> { | 740 | async fn get_global_cache_database(git_repo_path: &Path) -> Result<NostrLMDB> { |
| 742 | SQLiteDatabase::open(if std::env::var("NGITTEST").is_err() { | 741 | NostrLMDB::open(if std::env::var("NGITTEST").is_err() { |
| 743 | create_dir_all(get_dirs()?.cache_dir()).context(format!( | 742 | create_dir_all(get_dirs()?.cache_dir()).context(format!( |
| 744 | "cannot create cache directory in: {:?}", | 743 | "cannot create cache directory in: {:?}", |
| 745 | get_dirs()?.cache_dir() | 744 | get_dirs()?.cache_dir() |
| 746 | ))?; | 745 | ))?; |
| 747 | get_dirs()?.cache_dir().join("nostr-cache.sqlite") | 746 | get_dirs()?.cache_dir().join("nostr-cache.lmdb") |
| 748 | } else { | 747 | } else { |
| 749 | git_repo_path.join(".git/test-global-cache.sqlite") | 748 | git_repo_path.join(".git/test-global-cache.lmdb") |
| 750 | }) | 749 | }) |
| 751 | .await | ||
| 752 | .context("cannot open ngit global nostr cache database") | 750 | .context("cannot open ngit global nostr cache database") |
| 753 | } | 751 | } |
| 754 | 752 | ||
| @@ -761,7 +759,7 @@ pub async fn get_events_from_cache( | |||
| 761 | .query(filters.clone()) | 759 | .query(filters.clone()) |
| 762 | .await | 760 | .await |
| 763 | .context( | 761 | .context( |
| 764 | "cannot execute query on opened git repo nostr cache database .git/nostr-cache.sqlite", | 762 | "cannot execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", |
| 765 | ) | 763 | ) |
| 766 | } | 764 | } |
| 767 | 765 | ||