bugfix: txn failed
`ERROR notedeck_columns::timeline: setup_new_timeline: database error: Transaction failed` Reproduce by creating column, deleting it, then trying to create it again. Before this fix, it was blank. Now it displays correctly Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -482,6 +482,7 @@ pub fn merge_sorted_vecs<T: Ord + Copy>(vec1: &[T], vec2: &[T]) -> (Vec<T>, Merg
|
|||||||
pub fn setup_new_timeline(
|
pub fn setup_new_timeline(
|
||||||
timeline: &mut Timeline,
|
timeline: &mut Timeline,
|
||||||
ndb: &Ndb,
|
ndb: &Ndb,
|
||||||
|
txn: &Transaction,
|
||||||
subs: &mut Subscriptions,
|
subs: &mut Subscriptions,
|
||||||
pool: &mut RelayPool,
|
pool: &mut RelayPool,
|
||||||
note_cache: &mut NoteCache,
|
note_cache: &mut NoteCache,
|
||||||
@@ -489,7 +490,7 @@ pub fn setup_new_timeline(
|
|||||||
) {
|
) {
|
||||||
// if we're ready, setup local subs
|
// if we're ready, setup local subs
|
||||||
if is_timeline_ready(ndb, pool, note_cache, timeline) {
|
if is_timeline_ready(ndb, pool, note_cache, timeline) {
|
||||||
if let Err(err) = setup_timeline_nostrdb_sub(ndb, note_cache, timeline) {
|
if let Err(err) = setup_timeline_nostrdb_sub(ndb, txn, note_cache, timeline) {
|
||||||
error!("setup_new_timeline: {err}");
|
error!("setup_new_timeline: {err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -616,6 +617,7 @@ fn fetch_contact_list(
|
|||||||
|
|
||||||
fn setup_initial_timeline(
|
fn setup_initial_timeline(
|
||||||
ndb: &Ndb,
|
ndb: &Ndb,
|
||||||
|
txn: &Transaction,
|
||||||
timeline: &mut Timeline,
|
timeline: &mut Timeline,
|
||||||
note_cache: &mut NoteCache,
|
note_cache: &mut NoteCache,
|
||||||
filters: &[Filter],
|
filters: &[Filter],
|
||||||
@@ -647,14 +649,13 @@ fn setup_initial_timeline(
|
|||||||
lim += filter.limit().unwrap_or(1) as i32;
|
lim += filter.limit().unwrap_or(1) as i32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let txn = Transaction::new(ndb)?;
|
|
||||||
let notes: Vec<NoteRef> = ndb
|
let notes: Vec<NoteRef> = ndb
|
||||||
.query(&txn, filters, lim)?
|
.query(txn, filters, lim)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(NoteRef::from_query_result)
|
.map(NoteRef::from_query_result)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
timeline.insert_new(&txn, ndb, note_cache, ¬es);
|
timeline.insert_new(txn, ndb, note_cache, ¬es);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -665,7 +666,8 @@ pub fn setup_initial_nostrdb_subs(
|
|||||||
timeline_cache: &mut TimelineCache,
|
timeline_cache: &mut TimelineCache,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (_kind, timeline) in timeline_cache.timelines.iter_mut() {
|
for (_kind, timeline) in timeline_cache.timelines.iter_mut() {
|
||||||
if let Err(err) = setup_timeline_nostrdb_sub(ndb, note_cache, timeline) {
|
let txn = Transaction::new(ndb).expect("txn");
|
||||||
|
if let Err(err) = setup_timeline_nostrdb_sub(ndb, &txn, note_cache, timeline) {
|
||||||
error!("setup_initial_nostrdb_subs: {err}");
|
error!("setup_initial_nostrdb_subs: {err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -675,6 +677,7 @@ pub fn setup_initial_nostrdb_subs(
|
|||||||
|
|
||||||
fn setup_timeline_nostrdb_sub(
|
fn setup_timeline_nostrdb_sub(
|
||||||
ndb: &Ndb,
|
ndb: &Ndb,
|
||||||
|
txn: &Transaction,
|
||||||
note_cache: &mut NoteCache,
|
note_cache: &mut NoteCache,
|
||||||
timeline: &mut Timeline,
|
timeline: &mut Timeline,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
@@ -684,7 +687,7 @@ fn setup_timeline_nostrdb_sub(
|
|||||||
.ok_or(Error::App(notedeck::Error::empty_contact_list()))?
|
.ok_or(Error::App(notedeck::Error::empty_contact_list()))?
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
setup_initial_timeline(ndb, timeline, note_cache, &filter_state)?;
|
setup_initial_timeline(ndb, txn, timeline, note_cache, &filter_state)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -754,7 +757,8 @@ pub fn is_timeline_ready(
|
|||||||
// we just switched to the ready state, we should send initial
|
// we just switched to the ready state, we should send initial
|
||||||
// queries and setup the local subscription
|
// queries and setup the local subscription
|
||||||
info!("Found contact list! Setting up local and remote contact list query");
|
info!("Found contact list! Setting up local and remote contact list query");
|
||||||
setup_initial_timeline(ndb, timeline, note_cache, &filter).expect("setup init");
|
let txn = Transaction::new(ndb).expect("txn");
|
||||||
|
setup_initial_timeline(ndb, &txn, timeline, note_cache, &filter).expect("setup init");
|
||||||
timeline
|
timeline
|
||||||
.filter
|
.filter
|
||||||
.set_relay_state(relay_id, FilterState::ready(filter.clone()));
|
.set_relay_state(relay_id, FilterState::ready(filter.clone()));
|
||||||
|
|||||||
@@ -637,6 +637,7 @@ pub fn render_add_column_routes(
|
|||||||
crate::timeline::setup_new_timeline(
|
crate::timeline::setup_new_timeline(
|
||||||
&mut timeline,
|
&mut timeline,
|
||||||
ctx.ndb,
|
ctx.ndb,
|
||||||
|
&txn,
|
||||||
&mut app.subscriptions,
|
&mut app.subscriptions,
|
||||||
ctx.pool,
|
ctx.pool,
|
||||||
ctx.note_cache,
|
ctx.note_cache,
|
||||||
@@ -669,15 +670,15 @@ pub fn render_add_column_routes(
|
|||||||
// source to be, so let;s create a timeline from that and
|
// source to be, so let;s create a timeline from that and
|
||||||
// add it to our list of timelines
|
// add it to our list of timelines
|
||||||
AlgoOption::LastPerPubkey(Decision::Decided(list_kind)) => {
|
AlgoOption::LastPerPubkey(Decision::Decided(list_kind)) => {
|
||||||
let maybe_timeline = {
|
let txn = Transaction::new(ctx.ndb).unwrap();
|
||||||
let txn = Transaction::new(ctx.ndb).unwrap();
|
let maybe_timeline =
|
||||||
TimelineKind::last_per_pubkey(list_kind).into_timeline(&txn, ctx.ndb)
|
TimelineKind::last_per_pubkey(list_kind).into_timeline(&txn, ctx.ndb);
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(mut timeline) = maybe_timeline {
|
if let Some(mut timeline) = maybe_timeline {
|
||||||
crate::timeline::setup_new_timeline(
|
crate::timeline::setup_new_timeline(
|
||||||
&mut timeline,
|
&mut timeline,
|
||||||
ctx.ndb,
|
ctx.ndb,
|
||||||
|
&txn,
|
||||||
&mut app.subscriptions,
|
&mut app.subscriptions,
|
||||||
ctx.pool,
|
ctx.pool,
|
||||||
ctx.note_cache,
|
ctx.note_cache,
|
||||||
|
|||||||
Reference in New Issue
Block a user