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(ui): RoomListService::room is no longer async! #3551

Merged
merged 3 commits into from
Jun 13, 2024

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Jun 13, 2024

This patch is twofold:

  • it updates room_list_service::Room::new to take a &Client and a &RoomId instead of a SlidingSyncRoom. The SlidingSyncRoom is only used in Room::default_room_timeline_builder and is fetched there from the SlidingSync instance lazily. It confines the SlidingSyncRoom to one single method for Room now.
  • it makes RoomListService::room synchronous. It no longer reads a SlidingSyncRoom from SlidingSync, then it not needs to be async anymore. This patch replaces the RwLock of RoomListService::rooms from tokio::sync to std::sync.

…SyncRoom`.

This patch updates `room_list_service::Room::new` to take a `&Client`
and a `&RoomId` instead of a `SlidingSyncRoom`. The `SlidingSyncRoom` is
only used in `Room::default_room_timeline_builder` and is fetched there
from the `SlidingSync` instance lazily. It confines the
`SlidingSyncRoom` to one single method for `Room` now.
This patch makes `RoomListService::room` synchronous. It no longer reads
a `SlidingSyncRoom` from `SlidingSync`, then it not needs to be async
anymore. This patch replaces the `RwLock` of `RoomListService::rooms`
from `tokio::sync` to `std::sync`.

The patch updates all calls to `RoomListService::room` to remove the
`.await` point.
@Hywan Hywan requested a review from a team as a code owner June 13, 2024 12:52
@Hywan Hywan requested review from andybalaam and removed request for a team June 13, 2024 12:52
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

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

IT'S HAPPENING 🥳

I spotted a potential race condition that we could fix while we're touching this code, can you fix it before merging please?

crates/matrix-sdk-ui/src/room_list_service/mod.rs Outdated Show resolved Hide resolved
@bnjbvr bnjbvr removed the request for review from andybalaam June 13, 2024 12:57
This patch replaces the `RwLock` by a `Mutex` in
`RoomListService::rooms` because:

1. it removes a race condition,
2. `RwLock` was used because the lock could have been taken for a long
   time due to the previous `.await` point. It's no longer the case, so we
   can blindly use a `Mutex` here.
@Hywan Hywan enabled auto-merge June 13, 2024 13:05
Copy link

codecov bot commented Jun 13, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.

Project coverage is 83.83%. Comparing base (01a36c9) to head (a7ff058).
Report is 5 commits behind head on main.

Files Patch % Lines
crates/matrix-sdk-ui/src/room_list_service/mod.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3551   +/-   ##
=======================================
  Coverage   83.83%   83.83%           
=======================================
  Files         253      253           
  Lines       25843    25843           
=======================================
  Hits        21666    21666           
  Misses       4177     4177           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hywan Hywan merged commit 5178cbb into matrix-org:main Jun 13, 2024
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants