commit 4c61c337bdc6e6b18995318ad355fa2912f58987
parent 6a989e388b7609ba71dddbc3b8da5945450d78b4
Author: William Casarin <jb55@jb55.com>
Date: Mon, 2 Sep 2024 18:12:12 -0700
fix transaction crash regression when opening thread
small oversight
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/src/app.rs b/src/app.rs
@@ -267,7 +267,8 @@ fn try_process_event(damus: &mut Damus, ctx: &egui::Context) -> Result<()> {
let src = TimelineSource::column(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}");
}
} else {
diff --git a/src/timeline.rs b/src/timeline.rs
@@ -69,15 +69,13 @@ impl<'a> TimelineSource<'a> {
/// Check local subscriptions for new notes and insert them into
/// timelines (threads, columns)
- pub fn poll_notes_into_view(&self, app: &mut Damus) -> Result<()> {
- let sub = {
- let txn = Transaction::new(&app.ndb).expect("txn");
- if let Some(sub) = self.sub(app, &txn) {
+ pub fn poll_notes_into_view(&self, txn: &Transaction, app: &mut Damus) -> Result<()> {
+ let sub =
+ if let Some(sub) = self.sub(app, txn) {
sub
} else {
return Err(Error::no_active_sub());
- }
- };
+ };
let new_note_ids = app.ndb.poll_for_notes(sub, 100);
if new_note_ids.is_empty() {
@@ -86,18 +84,17 @@ impl<'a> TimelineSource<'a> {
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());
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
} 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;
};
- UnknownIds::update_from_note(&txn, app, ¬e);
+ UnknownIds::update_from_note(txn, app, ¬e);
let created_at = note.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 reversed = false;
- self.view(app, &txn, ViewFilter::NotesAndReplies)
+ self.view(app, txn, ViewFilter::NotesAndReplies)
.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);
}
diff --git a/src/ui/thread.rs b/src/ui/thread.rs
@@ -71,7 +71,7 @@ impl<'a> ThreadView<'a> {
};
// 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}");
}