feat: compute and cache RoomInfo::active_service_members#6537
Conversation
45f313e to
88a8cc5
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6537 +/- ##
==========================================
- Coverage 89.93% 89.92% -0.01%
==========================================
Files 381 381
Lines 106780 106867 +87
Branches 106780 106867 +87
==========================================
+ Hits 96036 96105 +69
- Misses 7096 7105 +9
- Partials 3648 3657 +9 ☔ View full report in Codecov by Sentry. |
51c245a to
1a6b534
Compare
RoomInfo::active_service_membersRoomInfo::active_service_members
This will be used as a cache for the computed value.
20a48b4 to
53e84fa
Compare
|
I rebased the PR to solve the conflicts, since I think you still hadn't started reviewing it. The changes should be minimal anyway, just using the new |
poljar
left a comment
There was a problem hiding this comment.
Some commits seem like they won't compile, please fix this.
I left some other minor nits, but generally this looks fine.
Don't forget some changelog entries.
| pub async fn update_active_service_members(&self) -> StoreResult<Option<Vec<RoomMember>>> { | ||
| if let Some(service_members) = self.service_members() { |
There was a problem hiding this comment.
We need to document this new behavior in the docs of this method.
| } | ||
|
|
||
| trace!( | ||
| "Updating active service members ({}) in room {:?}", |
There was a problem hiding this comment.
Using Debug for the room ID instead of Display might not yield the result you'd want, i.e.:
println!("{room_id}, {room_id:?}");Will yield:
!a:b.c, "!a:b.c"
| // Re-calculate active service members | ||
| self.update_active_service_members().await?; | ||
|
|
There was a problem hiding this comment.
Why is this done here as well? We didn't receive a remote echo from the /sync nor did we sync the members yet.
This will contain the incorrect value and it will be recomputed when we sync the members.
| if new_active_service_member_count != current_active_service_member_count { | ||
| self.update_and_save_room_info(|mut info| { | ||
| info.update_active_service_member_count(Some(new_active_service_member_count)); | ||
| (info, RoomInfoNotableUpdateReasons::ACTIVE_SERVICE_MEMBERS) |
There was a problem hiding this comment.
Agh, wrong rebase of a fixup. Thanks.
| /// Checks if the room belongs in the expected category based on whether it's a | ||
| /// DM or not. | ||
| fn matches(room: &RoomListItem, expected_kind: RoomCategory) -> bool { | ||
| let kind = if room.is_dm() { RoomCategory::People } else { RoomCategory::Group }; |
…active_service_members` The function will now store the computed value if it changed into the `RoomSummary` cache
…ing the room members of the room or when inviting someone
…the joined/invited user count or the heroes in a room change
This function will now also compute and store the active service members under the hood
This function will check the cached value and use it if available, falling back to using an approximate value that will be calculated synchronously if not.
…ring to have more accurate results
…::is_dm` Based on `Room::compute_is_dm`
Based on the cached and synchronous `Room::is_dm`
…when you receive a member hints event that doesn't match what you previously had
53e84fa to
26c8b59
Compare
Changes
RoomSummary::active_room_membersfield that will be used as a cache.Room::active_service_memberstoRoom::update_active_service_members, which will compute new values for the cache.async fn Room::is_dmtoRoom::compute_is_dmand also triggerRoom::update_active_service_membersto re-calculate the cache.Room::is_dmfunction that will use the cachedactive_service_membersvalue or calculate an approximate value as a fallback.Room::compute_is_dmandRoom::is_dminRoomInfo,NotificationRoomInfoandSpaceRoom.Motivation
For both the room list filtering and the
SpaceRoominstances we can't rely on an accurate value computed in place, since those APIs are synchronous. The approximate value previously calculated could be wrong in several cases, so if we can compute a better one instead that should make the checks more accurate.CHANGELOG.mdfiles.Signed-off-by: