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>
This commit is contained in:
William Casarin
2024-08-03 11:34:06 -07:00
parent be0efd57e5
commit 51b4dfd3f3

View File

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