feat(ui): Reduce and refresh the batch_size growing sync-mode of invites in RoomListService

feat(ui): Reduce and refresh the `batch_size` growing sync-mode of `invites` in `RoomListService`
This commit is contained in:
Ivan Enderlin
2023-08-24 13:32:29 +02:00
committed by GitHub
2 changed files with 101 additions and 23 deletions

View File

@@ -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(100))
.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<dyn Action + Send + Sync>;
@@ -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)

View File

@@ -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]],
},
},
},