notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 51b4dfd3f33aa3b06ce9ec3370193f06a3050cfe
parent be0efd57e5504c3e8a55aa59f0dbeb885c36d6ec
Author: William Casarin <jb55@jb55.com>
Date:   Sat,  3 Aug 2024 11:34:06 -0700

temp fix crash due to race condition

we should fix the race condition though

Link: https://github.com/damus-io/nostrdb/issues/35
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/app.rs | 38++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/app.rs b/src/app.rs @@ -379,26 +379,24 @@ fn poll_notes_for_timeline<'a>( debug!("{} new notes! {:?}", new_note_ids.len(), new_note_ids); } - let new_refs: Vec<(Note, NoteRef)> = new_note_ids - .iter() - .map(|key| { - let note = damus.ndb.get_note_by_key(txn, *key).expect("no note??"); - let cached_note = damus - .note_cache_mut() - .cached_note_or_insert(*key, &note) - .clone(); - let _ = get_unknown_note_ids(&damus.ndb, &cached_note, txn, &note, *key, ids); - - let created_at = note.created_at(); - ( - note, - NoteRef { - key: *key, - created_at, - }, - ) - }) - .collect(); + let mut new_refs: Vec<(Note, NoteRef)> = Vec::with_capacity(new_note_ids.len()); + for key in new_note_ids { + let note = if let Ok(note) = damus.ndb.get_note_by_key(txn, key) { + note + } else { + error!("hit race condition in poll_notes_into_view: https://github.com/damus-io/nostrdb/issues/35 note {:?} was not added to timeline", key); + continue; + }; + + let cached_note = damus + .note_cache_mut() + .cached_note_or_insert(key, &note) + .clone(); + let _ = get_unknown_note_ids(&damus.ndb, &cached_note, txn, &note, key, ids); + + let created_at = note.created_at(); + new_refs.push((note, NoteRef { key, created_at })); + } // ViewFilter::NotesAndReplies {