fix transaction crash regression when opening thread

small oversight

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-09-02 18:12:12 -07:00
parent 6a989e388b
commit 4c61c337bd
3 changed files with 11 additions and 13 deletions

View File

@@ -267,7 +267,8 @@ fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> {
let src = TimelineSource::column(timeline); let src = TimelineSource::column(timeline);
if let Ok(true) = is_timeline_ready(damus, timeline) { if let Ok(true) = is_timeline_ready(damus, timeline) {
if let Err(err) = src.poll_notes_into_view(damus) { let txn = Transaction::new(&damus.ndb).expect("txn");
if let Err(err) = src.poll_notes_into_view(&txn, damus) {
error!("poll_notes_into_view: {err}"); error!("poll_notes_into_view: {err}");
} }
} else { } else {

View File

@@ -69,14 +69,12 @@ impl<'a> TimelineSource<'a> {
/// Check local subscriptions for new notes and insert them into /// Check local subscriptions for new notes and insert them into
/// timelines (threads, columns) /// timelines (threads, columns)
pub fn poll_notes_into_view(&self, app: &mut Damus) -> Result<()> { pub fn poll_notes_into_view(&self, txn: &Transaction, app: &mut Damus) -> Result<()> {
let sub = { let sub =
let txn = Transaction::new(&app.ndb).expect("txn"); if let Some(sub) = self.sub(app, txn) {
if let Some(sub) = self.sub(app, &txn) {
sub sub
} else { } else {
return Err(Error::no_active_sub()); return Err(Error::no_active_sub());
}
}; };
let new_note_ids = app.ndb.poll_for_notes(sub, 100); let new_note_ids = app.ndb.poll_for_notes(sub, 100);
@@ -86,18 +84,17 @@ impl<'a> TimelineSource<'a> {
debug!("{} new notes! {:?}", new_note_ids.len(), new_note_ids); debug!("{} new notes! {:?}", new_note_ids.len(), new_note_ids);
} }
let txn = Transaction::new(&app.ndb).expect("txn");
let mut new_refs: Vec<(Note, NoteRef)> = Vec::with_capacity(new_note_ids.len()); let mut new_refs: Vec<(Note, NoteRef)> = Vec::with_capacity(new_note_ids.len());
for key in new_note_ids { for key in new_note_ids {
let note = if let Ok(note) = app.ndb.get_note_by_key(&txn, key) { let note = if let Ok(note) = app.ndb.get_note_by_key(txn, key) {
note note
} else { } 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); 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; continue;
}; };
UnknownIds::update_from_note(&txn, app, &note); UnknownIds::update_from_note(txn, app, &note);
let created_at = note.created_at(); let created_at = note.created_at();
new_refs.push((note, NoteRef { key, created_at })); new_refs.push((note, NoteRef { key, created_at }));
@@ -115,7 +112,7 @@ impl<'a> TimelineSource<'a> {
let refs: Vec<NoteRef> = new_refs.iter().map(|(_note, nr)| *nr).collect(); let refs: Vec<NoteRef> = new_refs.iter().map(|(_note, nr)| *nr).collect();
let reversed = false; let reversed = false;
self.view(app, &txn, ViewFilter::NotesAndReplies) self.view(app, txn, ViewFilter::NotesAndReplies)
.insert(&refs, reversed); .insert(&refs, reversed);
} }
@@ -134,7 +131,7 @@ impl<'a> TimelineSource<'a> {
} }
} }
self.view(app, &txn, ViewFilter::Notes) self.view(app, txn, ViewFilter::Notes)
.insert(&filtered_refs, reversed); .insert(&filtered_refs, reversed);
} }

View File

@@ -71,7 +71,7 @@ impl<'a> ThreadView<'a> {
}; };
// poll for new notes and insert them into our existing notes // poll for new notes and insert them into our existing notes
if let Err(e) = TimelineSource::Thread(root_id).poll_notes_into_view(self.app) { if let Err(e) = TimelineSource::Thread(root_id).poll_notes_into_view(&txn, self.app) {
error!("Thread::poll_notes_into_view: {e}"); error!("Thread::poll_notes_into_view: {e}");
} }