atagen

matrix-rust-sdk

public
Star0
Watch0

Commit a0e7d274a279

tarball

atagen <boss@atagen.co>2026-10-28 05:03 UTC

3 files changed+47-5
room-list: let the sync service set the growing batch size of the all rooms list

tuwunel resends every room in the requested range each time the list grows, so a 399 room account received most rooms four or five times at the default batch of 100, each repeat a round of event cache work. `SyncServiceBuilder::with_room_list_growing_batch_size` lets a client grow in fewer steps, and the default stays 100.
Modified file: crates/matrix-sdk-ui/src/room_list_service/mod.rs+6 additions
@@ -496,6 +496,12 @@ impl RoomListService {
496496 self.state_machine.subscribe()
497497 }
498498
499+ /// Set how many rooms each step of the `all_rooms` list's growing sync asks
500+ /// for, from the next time the list starts growing.
501+ pub fn set_growing_batch_size(&self, batch_size: u32) {
502+ self.state_machine.set_growing_batch_size(batch_size);
503+ }
504+
499505 async fn list_for(&self, sliding_sync_list_name: &str) -> Result<RoomList, Error> {
500506 RoomList::new(&self.client, &self.sliding_sync, sliding_sync_list_name, self.state()).await
501507 }
Modified file: crates/matrix-sdk-ui/src/room_list_service/state.rs+25 additions−5 deletions
@@ -14,7 +14,13 @@
1414
1515 //! States and actions for the `RoomList` state machine.
1616
17-use std::{future::ready, sync::Mutex};
17+use std::{
18+ future::ready,
19+ sync::{
20+ Mutex,
21+ atomic::{AtomicU32, Ordering},
22+ },
23+};
1824
1925 use eyeball::{SharedObservable, Subscriber};
2026 use matrix_sdk::{SlidingSync, SlidingSyncMode, sliding_sync::Range};
@@ -78,6 +84,9 @@ pub struct StateMachine {
7884 ///
7985 /// To be used in coordination with `Self::last_state_update_time`.
8086 state_lifespan: Duration,
87+
88+ /// The `batch_size` of the growing sync-mode of the `ALL_ROOMS_LIST_NAME` list.
89+ growing_batch_size: AtomicU32,
8190 }
8291
8392 impl StateMachine {
@@ -86,9 +95,14 @@ impl StateMachine {
8695 state: SharedObservable::new(State::Init),
8796 last_state_update_time: Mutex::new(Instant::now()),
8897 state_lifespan: DEFAULT_STATE_LIFESPAN,
98+ growing_batch_size: AtomicU32::new(ALL_ROOMS_DEFAULT_GROWING_BATCH_SIZE),
8999 }
90100 }
91101
102+ pub(super) fn set_growing_batch_size(&self, batch_size: u32) {
103+ self.growing_batch_size.store(batch_size, Ordering::SeqCst);
104+ }
105+
92106 /// Get the current state.
93107 pub(super) fn get(&self) -> State {
94108 self.state.get()
@@ -123,7 +137,8 @@ impl StateMachine {
123137 Init => SettingUp,
124138
125139 SettingUp | Recovering => {
126- set_all_rooms_to_growing_sync_mode(sliding_sync).await?;
140+ let batch_size = self.growing_batch_size.load(Ordering::SeqCst);
141+ set_all_rooms_to_growing_sync_mode(sliding_sync, batch_size).await?;
127142 Running
128143 }
129144
@@ -165,10 +180,13 @@ impl StateMachine {
165180 }
166181 }
167182
168-async fn set_all_rooms_to_growing_sync_mode(sliding_sync: &SlidingSync) -> Result<(), Error> {
183+async fn set_all_rooms_to_growing_sync_mode(
184+ sliding_sync: &SlidingSync,
185+ batch_size: u32,
186+) -> Result<(), Error> {
169187 sliding_sync
170188 .on_list(ALL_ROOMS_LIST_NAME, |list| {
171- list.set_sync_mode(SlidingSyncMode::new_growing(ALL_ROOMS_DEFAULT_GROWING_BATCH_SIZE));
189+ list.set_sync_mode(SlidingSyncMode::new_growing(batch_size));
172190
173191 ready(())
174192 })
@@ -388,7 +406,9 @@ mod tests {
388406 );
389407
390408 // Run the action!
391- set_all_rooms_to_growing_sync_mode(sliding_sync).await.unwrap();
409+ set_all_rooms_to_growing_sync_mode(sliding_sync, ALL_ROOMS_DEFAULT_GROWING_BATCH_SIZE)
410+ .await
411+ .unwrap();
392412
393413 // List is still present, in Growing mode.
394414 assert_eq!(
Modified file: crates/matrix-sdk-ui/src/sync_service.rs+16 additions
@@ -797,6 +797,9 @@ pub struct SyncServiceBuilder {
797797 /// State events the room list service requests on top of its defaults.
798798 room_list_extra_required_state: Vec<(StateEventType, String)>,
799799
800+ /// How many rooms each step of the room list's growing sync asks for.
801+ room_list_growing_batch_size: Option<u32>,
802+
800803 /// The parent tracing span to use for the tasks within this service.
801804 ///
802805 /// Normally this will be [`Span::none`], but it may be useful to assign a
@@ -815,6 +818,7 @@ impl SyncServiceBuilder {
815818 room_list_conn_id: DEFAULT_CONNECTION_ID.to_owned(),
816819 room_list_timeline_limit: DEFAULT_LIST_TIMELINE_LIMIT,
817820 room_list_extra_required_state: Vec::new(),
821+ room_list_growing_batch_size: None,
818822 parent_span: Span::none(),
819823 }
820824 }
@@ -865,6 +869,14 @@ impl SyncServiceBuilder {
865869 self
866870 }
867871
872+ /// How many rooms each step of the room list's growing sync asks for, 100
873+ /// by default. Servers that resend every room in the grown range resend a
874+ /// large account's rooms once per step.
875+ pub fn with_room_list_growing_batch_size(mut self, batch_size: u32) -> Self {
876+ self.room_list_growing_batch_size = Some(batch_size);
877+ self
878+ }
879+
868880 /// Set the parent tracing span to be used for the tasks within this
869881 /// service.
870882 pub fn with_parent_span(mut self, parent_span: Span) -> Self {
@@ -886,6 +898,7 @@ impl SyncServiceBuilder {
886898 room_list_conn_id,
887899 room_list_timeline_limit,
888900 room_list_extra_required_state,
901+ room_list_growing_batch_size,
889902 parent_span,
890903 } = self;
891904
@@ -900,6 +913,9 @@ impl SyncServiceBuilder {
900913 room_list_response_commit_hook,
901914 )
902915 .await?;
916+ if let Some(batch_size) = room_list_growing_batch_size {
917+ room_list.set_growing_batch_size(batch_size);
918+ }
903919
904920 let encryption_sync = Arc::new(EncryptionSyncService::new(client, None).await?);