notecrumbs

a nostr opengraph server build on nostrdb and egui
git clone git://jb55.com/notecrumbs
Log | Files | Refs | README | LICENSE

commit 7cd3b02168df5245a6b2a73de6b823b8acf52880
parent 5a5757c453f1bae5c82239887c43a662c974f37c
Author: alltheseas <alltheseas@users.noreply.github.com>
Date:   Thu, 23 Oct 2025 18:07:49 -0500

Avoid stale LMDB transactions when hydrating render data

Diffstat:
Msrc/render.rs | 52+++++++++++++++++++++++++++++++++++-----------------
1 file changed, 35 insertions(+), 17 deletions(-)

diff --git a/src/render.rs b/src/render.rs @@ -425,6 +425,33 @@ impl RenderData { }; } + fn hydrate_from_note_key(&mut self, ndb: &Ndb, note_key: NoteKey) -> Result<bool> { + let txn = Transaction::new(ndb)?; + let note = match ndb.get_note_by_key(&txn, note_key) { + Ok(note) => note, + Err(err) => { + debug!(?note_key, "note key not yet visible in transaction: {err}"); + return Ok(false); + } + }; + + if note.kind() == 0 { + match ndb.get_profilekey_by_pubkey(&txn, note.pubkey()) { + Ok(profile_key) => self.set_profile_key(profile_key), + Err(err) => { + debug!( + pubkey = %hex::encode(note.pubkey()), + "profile key not ready after note ingestion: {err}" + ); + } + } + } else { + self.set_note_key(note_key); + } + + Ok(true) + } + pub async fn complete( &mut self, ndb: Ndb, @@ -479,23 +506,14 @@ impl RenderData { let note_keys_len = note_keys.len(); - { - let txn = Transaction::new(&ndb)?; - - for note_key in note_keys { - let note = if let Ok(note) = ndb.get_note_by_key(&txn, note_key) { - note - } else { - error!("race condition in RenderData::complete?"); - continue; - }; - - if note.kind() == 0 { - if let Ok(profile_key) = ndb.get_profilekey_by_pubkey(&txn, note.pubkey()) { - self.set_profile_key(profile_key); - } - } else { - self.set_note_key(note_key); + for note_key in note_keys { + match self.hydrate_from_note_key(&ndb, note_key) { + Ok(true) => {} + Ok(false) => { + // keep waiting; the outer loop will retry on the next batch + } + Err(err) => { + error!(?note_key, "failed to hydrate note from key: {err}"); } } }