From 3dbc00cd67c1a88fbe8a23c676b50d4d3cd02963 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 24 Aug 2023 10:36:04 +0200 Subject: [PATCH 1/2] feat(ui): Reduce the `batch_size` of `invites` in `RoomListService`. This patch changes the `batch_size` of the sliding sync list `invites` for `RoomListService`. Previous value was 100, new value is 20. For accounts that have a large number of invites, it won't slow the rendering of `visible_rooms`. --- crates/matrix-sdk-ui/src/room_list_service/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/matrix-sdk-ui/src/room_list_service/state.rs b/crates/matrix-sdk-ui/src/room_list_service/state.rs index c1be2f148..490195ea4 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/state.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/state.rs @@ -155,7 +155,7 @@ impl Action for AddInvitesList { sliding_sync .add_list( SlidingSyncList::builder(INVITES_LIST_NAME) - .sync_mode(SlidingSyncMode::new_growing(100)) + .sync_mode(SlidingSyncMode::new_growing(20)) .timeline_limit(0) .required_state(vec![ (StateEventType::RoomAvatar, "".to_owned()), From 55e8f2573b9f76d6ce5566c36897d95457b69927 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 24 Aug 2023 10:53:50 +0200 Subject: [PATCH 2/2] feat(ui): Add the `ResetInvitesListGrowingSyncMode` action in `RoomList`. Inside `RoomListService`, the `State` enum handles the transition from one state to another. In case of some `State::Error`, the `all_rooms` sliding sync was refreshed, i.e. its sync-mode was reset to its initial value. This patch also refreshes the `invites` sliding sync list! It adds the `ResetInvitesListGrowingSyncMode` action, and attaches it to the `refresh_lists` actions. New constants are added to represent default `batch_size` values for the growing sync-mode for various sliding sync list. It could be helpful for further maintenance. This patch finally adds and updates the tests accordingly. --- .../src/room_list_service/state.rs | 86 ++++++++++++++++++- .../tests/integration/room_list_service.rs | 38 ++++---- 2 files changed, 101 insertions(+), 23 deletions(-) diff --git a/crates/matrix-sdk-ui/src/room_list_service/state.rs b/crates/matrix-sdk-ui/src/room_list_service/state.rs index 490195ea4..6816d2836 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/state.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/state.rs @@ -131,12 +131,18 @@ impl Action for AddVisibleRoomsList { struct SetAllRoomsListToGrowingSyncMode; +/// Default `batch_size` for the growing sync-mode of the `ALL_ROOMS_LIST_NAME` +/// list. +pub const ALL_ROOMS_DEFAULT_GROWING_BATCH_SIZE: u32 = 200; + #[async_trait] impl Action for SetAllRoomsListToGrowingSyncMode { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync .on_list(ALL_ROOMS_LIST_NAME, |list| { - list.set_sync_mode(SlidingSyncMode::new_growing(200)); + list.set_sync_mode(SlidingSyncMode::new_growing( + ALL_ROOMS_DEFAULT_GROWING_BATCH_SIZE, + )); ready(()) }) @@ -149,13 +155,17 @@ impl Action for SetAllRoomsListToGrowingSyncMode { struct AddInvitesList; +/// Default `batch_size` for the growing sync-mode of the `INVITES_LIST_NAME` +/// list. +pub const INVITES_DEFAULT_GROWING_BATCH_SIZE: u32 = 20; + #[async_trait] impl Action for AddInvitesList { async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { sliding_sync .add_list( SlidingSyncList::builder(INVITES_LIST_NAME) - .sync_mode(SlidingSyncMode::new_growing(20)) + .sync_mode(SlidingSyncMode::new_growing(INVITES_DEFAULT_GROWING_BATCH_SIZE)) .timeline_limit(0) .required_state(vec![ (StateEventType::RoomAvatar, "".to_owned()), @@ -177,6 +187,26 @@ impl Action for AddInvitesList { } } +struct ResetInvitesListGrowingSyncMode; + +#[async_trait] +impl Action for ResetInvitesListGrowingSyncMode { + async fn run(&self, sliding_sync: &SlidingSync) -> Result<(), Error> { + sliding_sync + .on_list(INVITES_LIST_NAME, |list| { + list.set_sync_mode(SlidingSyncMode::new_growing( + INVITES_DEFAULT_GROWING_BATCH_SIZE, + )); + + ready(()) + }) + .await + .ok_or_else(|| Error::UnknownList(INVITES_LIST_NAME.to_owned()))?; + + Ok(()) + } +} + /// Type alias to represent one action. type OneAction = Box; @@ -217,7 +247,7 @@ impl Actions { actions! { none => [], first_rooms_are_loaded => [SetAllRoomsListToGrowingSyncMode, AddVisibleRoomsList, AddInvitesList], - refresh_lists => [SetAllRoomsListToGrowingSyncMode], + refresh_lists => [SetAllRoomsListToGrowingSyncMode, ResetInvitesListGrowingSyncMode], } fn iter(&self) -> &[OneAction] { @@ -380,7 +410,55 @@ mod tests { sliding_sync .on_list(INVITES_LIST_NAME, |list| ready(matches!( list.sync_mode(), - SlidingSyncMode::Growing { batch_size, .. } if batch_size == 100 + SlidingSyncMode::Growing { batch_size, .. } if batch_size == 20 + ))) + .await, + Some(true) + ); + + Ok(()) + } + + #[async_test] + async fn test_action_reset_invites_list_growing_sync_mode() -> Result<(), Error> { + let room_list = new_room_list().await?; + let sliding_sync = room_list.sliding_sync(); + + // List is absent. + assert_eq!(sliding_sync.on_list(INVITES_LIST_NAME, |_list| ready(())).await, None); + + // Run the action! + AddInvitesList.run(sliding_sync).await?; + + // Change the growing sync-mode. + sliding_sync + .on_list(INVITES_LIST_NAME, |list| { + list.set_sync_mode(SlidingSyncMode::new_growing(42)); + + ready(()) + }) + .await + .unwrap(); + + assert_eq!( + sliding_sync + .on_list(INVITES_LIST_NAME, |list| ready(matches!( + list.sync_mode(), + SlidingSyncMode::Growing { batch_size, .. } if batch_size == 42 + ))) + .await, + Some(true) + ); + + // Run the action! + ResetInvitesListGrowingSyncMode.run(sliding_sync).await?; + + // List is still present, and reset. + assert_eq!( + sliding_sync + .on_list(INVITES_LIST_NAME, |list| ready(matches!( + list.sync_mode(), + SlidingSyncMode::Growing { batch_size, .. } if batch_size == 20 ))) .await, Some(true) diff --git a/crates/matrix-sdk-ui/tests/integration/room_list_service.rs b/crates/matrix-sdk-ui/tests/integration/room_list_service.rs index 7c08505a5..67d0fd57c 100644 --- a/crates/matrix-sdk-ui/tests/integration/room_list_service.rs +++ b/crates/matrix-sdk-ui/tests/integration/room_list_service.rs @@ -323,7 +323,7 @@ async fn test_sync_all_states() -> Result<(), Error> { "timeline_limit": 20, }, INVITES: { - "ranges": [[0, 99]], + "ranges": [[0, 19]], "required_state": [ ["m.room.avatar", ""], ["m.room.encryption", ""], @@ -539,7 +539,7 @@ async fn test_sync_resumes_from_previous_state() -> Result<(), Error> { "ranges": [[0, 19]], }, INVITES: { - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, }, @@ -683,7 +683,7 @@ async fn test_sync_resumes_from_error() -> Result<(), Error> { }, INVITES: { // Hello new list. - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, }, @@ -720,7 +720,7 @@ async fn test_sync_resumes_from_error() -> Result<(), Error> { }, INVITES: { // The range hasn't been modified due to previous error. - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, }, @@ -731,7 +731,7 @@ async fn test_sync_resumes_from_error() -> Result<(), Error> { "count": 410, }, INVITES: { - "count": 3, + "count": 30, } }, "rooms": {}, @@ -756,7 +756,7 @@ async fn test_sync_resumes_from_error() -> Result<(), Error> { }, INVITES: { // Despites the error, the range has made progress. - "ranges": [[0, 2]], + "ranges": [[0, 29]], }, }, }, @@ -788,8 +788,8 @@ async fn test_sync_resumes_from_error() -> Result<(), Error> { "ranges": [[5, 10]], }, INVITES: { - // Despites the error, the range is kept. - "ranges": [[0, 2]], + // Due to the error, the range is reset to its initial range. + "ranges": [[0, 19]], } }, }, @@ -800,7 +800,7 @@ async fn test_sync_resumes_from_error() -> Result<(), Error> { "count": 410, }, INVITES: { - "count": 0, + "count": 4, }, }, "rooms": {}, @@ -824,7 +824,7 @@ async fn test_sync_resumes_from_error() -> Result<(), Error> { }, INVITES: { // The range is making progress. - "ranges": [[0, 0]], + "ranges": [[0, 3]], }, }, }, @@ -857,7 +857,7 @@ async fn test_sync_resumes_from_error() -> Result<(), Error> { }, INVITES: { // The range is kept as it was. - "ranges": [[0, 0]], + "ranges": [[0, 3]], }, }, }, @@ -892,7 +892,7 @@ async fn test_sync_resumes_from_error() -> Result<(), Error> { }, INVITES: { // The range is kept as it was. - "ranges": [[0, 0]], + "ranges": [[0, 3]], }, }, }, @@ -969,7 +969,7 @@ async fn test_sync_resumes_from_terminated() -> Result<(), Error> { }, INVITES: { // Hello new list. - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, }, @@ -1012,7 +1012,7 @@ async fn test_sync_resumes_from_terminated() -> Result<(), Error> { }, INVITES: { // The range hasn't been modified due to previous termination. - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, }, @@ -1338,7 +1338,7 @@ async fn test_entries_stream() -> Result<(), Error> { "ranges": [[0, 19]], }, INVITES: { - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, }, @@ -1486,7 +1486,7 @@ async fn test_entries_stream_with_filters() -> Result<(), Error> { "ranges": [[0, 19]], }, INVITES: { - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, }, @@ -1714,7 +1714,7 @@ async fn test_invites_stream() -> Result<(), Error> { "ranges": [[0, 19]], }, INVITES: { - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, }, @@ -2399,7 +2399,7 @@ async fn test_input_viewport() -> Result<(), Error> { "timeline_limit": 20, }, INVITES: { - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, }, @@ -2435,7 +2435,7 @@ async fn test_input_viewport() -> Result<(), Error> { "ranges": [[10, 15], [20, 25]], }, INVITES: { - "ranges": [[0, 99]], + "ranges": [[0, 19]], }, }, },