From 0aae761da47f818e75857e6af9a94d848fcaea67 Mon Sep 17 00:00:00 2001 From: Benjamin Lee Date: Fri, 3 May 2024 17:15:59 -0700 Subject: [PATCH] skip left/invited rooms with no updates in /sync Before this change we were just returning an empty object for left or invited rooms that don't have any updates. This is valid coloredding to the spec, but it's a nicer to debug if they are omitted it and results in a little less network traffic. For joined rooms, we are already skipping empty updates. With filtering support, it's much more common to have sync responses where many rooms are empty, because all of the state/timeline events may be filtered out. --- src/api/client_server/sync.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/api/client_server/sync.rs b/src/api/client_server/sync.rs index 8322a978..ff2b25a6 100644 --- a/src/api/client_server/sync.rs +++ b/src/api/client_server/sync.rs @@ -460,16 +460,16 @@ async fn sync_helper( } }; - left_rooms.insert( - room_id.into_owned(), - LeftRoom { - account_data: RoomAccountData { - events: Vec::new(), - }, - timeline, - state, + let left_room = LeftRoom { + account_data: RoomAccountData { + events: Vec::new(), }, - ); + timeline, + state, + }; + if !left_room.is_empty() { + left_rooms.insert(room_id.into_owned(), left_room); + } } let mut invited_rooms = BTreeMap::new(); @@ -519,14 +519,14 @@ async fn sync_helper( continue; } - invited_rooms.insert( - room_id.into_owned(), - InvitedRoom { - invite_state: InviteState { - events: invite_state_events, - }, + let invited_room = InvitedRoom { + invite_state: InviteState { + events: invite_state_events, }, - ); + }; + if !invited_room.is_empty() { + invited_rooms.insert(room_id.into_owned(), invited_room); + } } for user_id in left_encrypted_users {