commit b5d543f35cf428811f8f8f0c5cfc571db23d8a40
parent 1ebe408f5b7778063de9057ad5ab6a76e91e9c2f
Author: kernelkind <kernelkind@gmail.com>
Date: Wed, 25 Feb 2026 16:55:07 -0500
refactor(nip51-set): extract local cache/sub loader
Extract the shared nip51 cache preloading and local NostrDB subscription setup into a helper used by Nip51SetCache::new.
This keeps behavior unchanged while making it easier to add onboarding-specific constructors in a follow-up commit.
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/crates/notedeck/src/nip51_set.rs b/crates/notedeck/src/nip51_set.rs
@@ -23,25 +23,8 @@ impl Nip51SetCache {
nip51_set_filter: Vec<Filter>,
) -> Option<Self> {
let subid = Uuid::new_v4().to_string();
- let mut cached_notes = IndexMap::default();
-
- let notes: Option<Vec<Note>> = if let Ok(results) = ndb.query(txn, &nip51_set_filter, 500) {
- Some(results.into_iter().map(|r| r.note).collect())
- } else {
- None
- };
-
- if let Some(notes) = notes {
- add(notes, &mut cached_notes, ndb, txn, unknown_ids);
- }
-
- let sub = match ndb.subscribe(&nip51_set_filter) {
- Ok(sub) => sub,
- Err(e) => {
- tracing::error!("Could not ndb subscribe: {e}");
- return None;
- }
- };
+ let (cached_notes, sub) =
+ load_cached_notes_and_local_sub(ndb, txn, unknown_ids, &nip51_set_filter)?;
pool.subscribe(subid.clone(), nip51_set_filter);
Some(Self {
@@ -87,6 +70,35 @@ impl Nip51SetCache {
}
}
+fn load_cached_notes_and_local_sub(
+ ndb: &Ndb,
+ txn: &Transaction,
+ unknown_ids: &mut UnknownIds,
+ nip51_set_filter: &[Filter],
+) -> Option<(IndexMap<PackId, Nip51Set>, nostrdb::Subscription)> {
+ let mut cached_notes = IndexMap::default();
+
+ let notes: Option<Vec<Note>> = if let Ok(results) = ndb.query(txn, nip51_set_filter, 500) {
+ Some(results.into_iter().map(|r| r.note).collect())
+ } else {
+ None
+ };
+
+ if let Some(notes) = notes {
+ add(notes, &mut cached_notes, ndb, txn, unknown_ids);
+ }
+
+ let sub = match ndb.subscribe(nip51_set_filter) {
+ Ok(sub) => sub,
+ Err(e) => {
+ tracing::error!("Could not ndb subscribe: {e}");
+ return None;
+ }
+ };
+
+ Some((cached_notes, sub))
+}
+
#[profiling::function]
fn add(
notes: Vec<Note>,