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.
This commit is contained in:
Benjamin Lee 2024-05-03 17:15:59 -07:00
parent e6f2b6c9ad
commit 4e1d091bbc
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4

View file

@ -262,14 +262,14 @@ pub(crate) async fn sync_events_route(
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 {
@ -1158,16 +1158,16 @@ async fn handle_left_room(
}
};
left_rooms.insert(
room_id.clone(),
LeftRoom {
account_data: RoomAccountData {
events: Vec::new(),
},
timeline,
state,
let left_room = LeftRoom {
account_data: RoomAccountData {
events: Vec::new(),
},
);
timeline,
state,
};
if !left_rooms.is_empty() {
left_rooms.insert(room_id.clone(), left_room);
}
Ok(())
}