Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Only restart growing the allRooms list in case of errors #2208

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions crates/matrix-sdk-ui/src/room_list_service/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ impl State {
}

Running => {
// Refresh the lists.
(Running, Actions::refresh_lists())
// Refresh the lists only if our sync ran into an error (in particular,
// when the session was invalidated by the server). Otherwise, keep on
// iterating on the previous list.
if matches!(self, Error { .. }) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the big match can be simplified as is:

        let (next_state, actions) = match self {
            Init => (SettingUp, Actions::none()),
            SettingUp => (Running, Actions::first_rooms_are_loaded()),
            Running => (Running, Actions::none()),
            Terminated { from: previous_state } => match previous_state.as_ref() {
                Error { .. } | Terminated { .. } => {
                    unreachable!("…");
                }

                state => {
                    // Do nothing.
                    (state.to_owned(), Actions::none())
                }
            },
            Error { from: previous_state } => match previous_state.as_ref() {
                Error { .. } | Terminated { .. } => {
                    unreachable!("…");
                }

                Running => {
                    // Refresh the lists.
                    (Running, Actions::refresh_lists())
                }

                state => {
                    // Do nothing.
                    (state.to_owned(), Actions::none())
                }
            },
      };

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up here, #2217.

(Running, Actions::refresh_lists())
} else {
(Running, Actions::none())
}
}

Error { .. } | Terminated { .. } => {
Expand Down
23 changes: 11 additions & 12 deletions crates/matrix-sdk-ui/tests/integration/room_list_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,9 @@ async fn test_sync_resumes_from_terminated() -> Result<(), Error> {
assert request >= {
"lists": {
ALL_ROOMS: {
// In `Running`, the sync-mode is still growing, but the range
// hasn't been modified due to previous termination.
"ranges": [[0, 49]],
// In `Running`, the sync-mode is still growing, the previous termination
// didn't restart the whole growing.
"ranges": [[0, 99]],
},
VISIBLE_ROOMS: {
// We have set a viewport, which reflects here.
Expand Down Expand Up @@ -1013,9 +1013,9 @@ async fn test_sync_resumes_from_terminated() -> Result<(), Error> {
assert request >= {
"lists": {
ALL_ROOMS: {
// In `Running`, the sync-mode is still growing, but the range
// hasn't been modified due to the previous termination.
"ranges": [[0, 49]],
// In `Running`, the sync-mode is still growing, the previous termination
// didn't restart the whole growing.
"ranges": [[0, 109]],
},
VISIBLE_ROOMS: {
// Despites the termination, the range is kept.
Expand Down Expand Up @@ -1049,8 +1049,8 @@ async fn test_sync_resumes_from_terminated() -> Result<(), Error> {
assert request >= {
"lists": {
ALL_ROOMS: {
// No termination. The range is making progress.
"ranges": [[0, 99]],
// No termination.
"ranges": [[0, 109]],
},
VISIBLE_ROOMS: {
// No termination. The range is still here.
Expand Down Expand Up @@ -1088,10 +1088,9 @@ async fn test_sync_resumes_from_terminated() -> Result<(), Error> {
assert request >= {
"lists": {
ALL_ROOMS: {
// A termination was received at the previous sync iteration.
// The list is still in growing sync-mode, but its range has
// been reset.
"ranges": [[0, 49]],
// The termination doesn't invalidate the range, we're still in the stable
// state.
"ranges": [[0, 109]],
},
VISIBLE_ROOMS: {
// The range is still here.
Expand Down