-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2022-2023 Yuki Kishimoto | ||
// Distributed under the MIT software license | ||
|
||
use std::time::{Duration, Instant}; | ||
|
||
use nostr::{EventBuilder, Filter, Keys, Kind, Metadata, Tag}; | ||
use nostr_sdk_db::memory::MemoryDatabase; | ||
use nostr_sdk_db::NostrDatabase; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let keys = Keys::generate(); | ||
let database = MemoryDatabase::new(); | ||
|
||
for i in 0..50_000 { | ||
let event = EventBuilder::new_text_note(format!("Event #{i}"), &[]) | ||
.to_event(&keys) | ||
.unwrap(); | ||
database.save_event(&event).await.unwrap(); | ||
|
||
let event = EventBuilder::new_text_note( | ||
format!("Reply to event #{i}"), | ||
&[ | ||
Tag::Event(event.id, None, None), | ||
Tag::PubKey(event.pubkey, None), | ||
], | ||
) | ||
.to_event(&keys) | ||
.unwrap(); | ||
database.save_event(&event).await.unwrap(); | ||
} | ||
|
||
for i in 0..10 { | ||
let metadata = Metadata::new().name(format!("Name #{i}")); | ||
let event = EventBuilder::set_metadata(metadata) | ||
.to_event(&keys) | ||
.unwrap(); | ||
database.save_event(&event).await.unwrap(); | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
} | ||
|
||
let now = Instant::now(); | ||
let events = database | ||
.query(vec![Filter::new() | ||
.kind(Kind::Metadata) | ||
.author(keys.public_key().to_string())]) | ||
.await | ||
.unwrap(); | ||
println!("{events:?}"); | ||
println!("Time: {} ns", now.elapsed().as_nanos()); | ||
} |