Skip to content

Commit cfa56ab

Browse files
jb55claude
andcommitted
fix: remove sync NDB queries that defeated async timeline loading
The outbox merge added setup_selected_account_timeline_subs() to the Initializing path, which ran synchronous ndb.query() + insert_new() on the UI thread for every timeline—exactly the blocking work the async TimelineLoader was created to avoid. Strip the queries from setup_initial_timeline, keeping only the local NDB subscription setup (try_add_local) needed by poll_notes_into_view. The heavy note-loading stays with the async loader. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 06e7127 commit cfa56ab

File tree

3 files changed

+7
-76
lines changed

3 files changed

+7
-76
lines changed

crates/notedeck_columns/src/app.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ pub(crate) fn setup_selected_account_timeline_subs(
373373
) {
374374
if let Err(err) = timeline::setup_initial_nostrdb_subs(
375375
app_ctx.ndb,
376-
app_ctx.note_cache,
377376
timeline_cache,
378-
app_ctx.unknown_ids,
379377
*app_ctx.accounts.selected_account_pubkey(),
380378
) {
381379
warn!("update_damus init: {err}");

crates/notedeck_columns/src/timeline/mod.rs

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -673,24 +673,19 @@ pub fn merge_sorted_vecs<T: Ord + Copy>(vec1: &[T], vec2: &[T]) -> (Vec<T>, Merg
673673
///
674674
/// We do this by maintaining this sub_id in the filter state, even when
675675
/// in the ready state. See: [`FilterReady`]
676-
#[allow(clippy::too_many_arguments)]
677676
pub fn setup_new_timeline(
678677
timeline: &mut Timeline,
679678
ndb: &Ndb,
680679
txn: &Transaction,
681680
scoped_subs: &mut ScopedSubApi<'_, '_>,
682-
note_cache: &mut NoteCache,
683681
since_optimize: bool,
684682
accounts: &Accounts,
685-
unknown_ids: &mut UnknownIds,
686683
) {
687684
let account_pk = *accounts.selected_account_pubkey();
688685

689686
// if we're ready, setup local subs
690687
if is_timeline_ready(ndb, scoped_subs, timeline, accounts) {
691-
if let Err(err) =
692-
setup_timeline_nostrdb_sub(ndb, txn, note_cache, timeline, unknown_ids, account_pk)
693-
{
688+
if let Err(err) = setup_initial_timeline(ndb, timeline, account_pk) {
694689
error!("setup_new_timeline: {err}");
695690
}
696691
}
@@ -812,102 +807,44 @@ pub fn fetch_people_list(ndb: &Ndb, txn: &Transaction, timeline: &mut Timeline)
812807
timeline.filter = FilterState::GotRemote;
813808
}
814809

810+
/// Set up the local NDB subscription for a timeline without running
811+
/// blocking queries. The actual note loading is handled by the async
812+
/// timeline loader.
815813
#[profiling::function]
816-
fn setup_initial_timeline(
817-
ndb: &Ndb,
818-
txn: &Transaction,
819-
timeline: &mut Timeline,
820-
note_cache: &mut NoteCache,
821-
unknown_ids: &mut UnknownIds,
822-
account_pk: Pubkey,
823-
) -> Result<()> {
814+
fn setup_initial_timeline(ndb: &Ndb, timeline: &mut Timeline, account_pk: Pubkey) -> Result<()> {
824815
let FilterState::Ready(filters) = &timeline.filter else {
825816
return Err(Error::App(notedeck::Error::empty_contact_list()));
826817
};
827818

828-
// some timelines are one-shot and a refreshed, like last_per_pubkey algo feed
819+
// some timelines are one-shot and refreshed, like last_per_pubkey algo feed
829820
if timeline.kind.should_subscribe_locally() {
830821
timeline
831822
.subscription
832823
.try_add_local(account_pk, ndb, filters);
833824
}
834825

835-
debug!(
836-
"querying nostrdb sub {:?} {:?}",
837-
timeline.subscription, timeline.filter
838-
);
839-
840-
let notes = {
841-
let mut notes = Vec::new();
842-
843-
for package in filters.local().packages {
844-
let mut lim = 0i32;
845-
for filter in package.filters {
846-
lim += filter.limit().unwrap_or(1) as i32;
847-
}
848-
849-
debug!("setup_initial_timeline: limit for local filter is {}", lim);
850-
851-
let cur_notes: Vec<NoteRef> = ndb
852-
.query(txn, package.filters, lim)?
853-
.into_iter()
854-
.map(NoteRef::from_query_result)
855-
.collect();
856-
tracing::debug!(
857-
"Found {} notes for kind: {:?}",
858-
cur_notes.len(),
859-
package.kind
860-
);
861-
notes.extend(&cur_notes);
862-
}
863-
864-
notes
865-
};
866-
867-
if let Some(pks) = timeline.insert_new(txn, ndb, note_cache, &notes) {
868-
pks.process(ndb, txn, unknown_ids);
869-
}
870-
871826
Ok(())
872827
}
873828

874829
#[profiling::function]
875830
pub fn setup_initial_nostrdb_subs(
876831
ndb: &Ndb,
877-
note_cache: &mut NoteCache,
878832
timeline_cache: &mut TimelineCache,
879-
unknown_ids: &mut UnknownIds,
880833
account_pk: Pubkey,
881834
) -> Result<()> {
882835
for (_kind, timeline) in timeline_cache {
883836
if timeline.subscription.dependers(&account_pk) == 0 {
884837
continue;
885838
}
886839

887-
let txn = Transaction::new(ndb).expect("txn");
888-
if let Err(err) =
889-
setup_timeline_nostrdb_sub(ndb, &txn, note_cache, timeline, unknown_ids, account_pk)
890-
{
840+
if let Err(err) = setup_initial_timeline(ndb, timeline, account_pk) {
891841
error!("setup_initial_nostrdb_subs: {err}");
892842
}
893843
}
894844

895845
Ok(())
896846
}
897847

898-
fn setup_timeline_nostrdb_sub(
899-
ndb: &Ndb,
900-
txn: &Transaction,
901-
note_cache: &mut NoteCache,
902-
timeline: &mut Timeline,
903-
unknown_ids: &mut UnknownIds,
904-
account_pk: Pubkey,
905-
) -> Result<()> {
906-
setup_initial_timeline(ndb, txn, timeline, note_cache, unknown_ids, account_pk)?;
907-
908-
Ok(())
909-
}
910-
911848
/// Check our timeline filter and see if we have any filter data ready.
912849
/// Our timelines may require additional data before it is functional. For
913850
/// example, when we have to fetch a contact list before we do the actual

crates/notedeck_columns/src/ui/add_column.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,8 @@ fn attach_timeline_column(
917917
ctx.ndb,
918918
&txn,
919919
&mut scoped_subs,
920-
ctx.note_cache,
921920
app.options.contains(AppOptions::SinceOptimize),
922921
ctx.accounts,
923-
ctx.unknown_ids,
924922
);
925923

926924
let route_kind = timeline.kind.clone();
@@ -1141,10 +1139,8 @@ fn handle_create_people_list(app: &mut Damus, ctx: &mut AppContext<'_>, col: usi
11411139
ctx.ndb,
11421140
&txn,
11431141
&mut scoped_subs,
1144-
ctx.note_cache,
11451142
app.options.contains(AppOptions::SinceOptimize),
11461143
ctx.accounts,
1147-
ctx.unknown_ids,
11481144
);
11491145

11501146
app.columns_mut(ctx.i18n, ctx.accounts)

0 commit comments

Comments
 (0)