@@ -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) ]
677676pub 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]
875830pub 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
0 commit comments