Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Include bundled aggregations in /sync and related fixes #11478

Merged
merged 14 commits into from
Dec 6, 2021
Merged
13 changes: 8 additions & 5 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ async def serialize_event(
event: The event being serialized.
time_now: The current time in milliseconds
bundle_aggregations: Whether to include the bundled aggregations for this
event.
event. Only applies to non-state events.
clokep marked this conversation as resolved.
Show resolved Hide resolved
**kwargs: Arguments to pass to `serialize_event`

Returns:
Expand All @@ -416,10 +416,13 @@ async def serialize_event(

serialized_event = serialize_event(event, time_now, **kwargs)

# If MSC1849 is enabled then we need to look if there are any relation
# aggregations we need to bundle in with the event.
# Do not bundle aggregations if the event has been redacted or if the event
# is a state event.
# Check if there are any bundled aggregations to include with the event.
#
# Do not bundle aggregations if any of the following at true:
#
# * Support is disabled via the configuration or the caller.
# * The event is a state event.
# * The event has been redacted.
if (
self._msc1849_enabled
and bundle_aggregations
Expand Down
8 changes: 5 additions & 3 deletions synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ async def handle_room(event: RoomsForUser) -> None:
d["invite"] = await self._event_serializer.serialize_event(
invite_event,
time_now,
# Don't bundle aggregations as this is a deprecated API.
bundle_aggregations=False,
as_client_event=as_client_event,
clokep marked this conversation as resolved.
Show resolved Hide resolved
)

Expand Down Expand Up @@ -232,7 +234,7 @@ async def handle_room(event: RoomsForUser) -> None:
d["state"] = await self._event_serializer.serialize_events(
current_state.values(),
time_now=time_now,
# No need to bundle aggregations for state events.
# Don't bundle aggregations as this is a deprecated API.
bundle_aggregations=False,
as_client_event=as_client_event,
)
Expand Down Expand Up @@ -383,7 +385,7 @@ async def _room_initial_sync_parted(
"end": await end_token.to_string(self.store),
},
"state": (
# No need to bundle aggregations for state events.
# Don't bundle aggregations as this is a deprecated API.
await self._event_serializer.serialize_events(
room_state.values(), time_now, bundle_aggregations=False
)
Expand All @@ -404,7 +406,7 @@ async def _room_initial_sync_joined(

# TODO: These concurrently
time_now = self.clock.time_msec()
# No need to bundle aggregations for state events.
# Don't bundle aggregations as this is a deprecated API.
state = await self._event_serializer.serialize_events(
current_state.values(), time_now, bundle_aggregations=False
)
Expand Down
7 changes: 1 addition & 6 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,7 @@ async def get_state_events(
room_state = room_state_events[membership_event_id]

now = self.clock.time_msec()
events = await self._event_serializer.serialize_events(
room_state.values(),
now,
# No need to bundle aggregations for state events.
bundle_aggregations=False,
)
events = await self._event_serializer.serialize_events(room_state.values(), now)
return events

async def get_joined_members(self, requester: Requester, room_id: str) -> dict:
Expand Down
6 changes: 1 addition & 5 deletions synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,7 @@ async def get_messages(

if state:
chunk["state"] = await self._event_serializer.serialize_events(
state,
time_now,
as_client_event=as_client_event,
# No need to bundle aggregations for state events.
bundle_aggregations=False,
state, time_now, as_client_event=as_client_event
)

return chunk
Expand Down
3 changes: 1 addition & 2 deletions synapse/handlers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,8 @@ async def search(
if state_results:
s = {}
for room_id, state_events in state_results.items():
# No need to bundle aggregations for state events.
s[room_id] = await self._event_serializer.serialize_events(
state_events, time_now, bundle_aggregations=False
state_events, time_now
)

rooms_cat_res["state"] = s
Expand Down
12 changes: 2 additions & 10 deletions synapse/rest/admin/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,7 @@ async def on_GET(
event_ids = await self.store.get_current_state_ids(room_id)
events = await self.store.get_events(event_ids.values())
now = self.clock.time_msec()
room_state = await self._event_serializer.serialize_events(
events.values(),
now,
# No need to bundle aggregations for state events.
bundle_aggregations=False,
)
room_state = await self._event_serializer.serialize_events(events.values(), now)
ret = {"state": room_state}

return HTTPStatus.OK, ret
Expand Down Expand Up @@ -788,10 +783,7 @@ async def on_GET(
results["events_after"], time_now
)
results["state"] = await self._event_serializer.serialize_events(
results["state"],
time_now,
# No need to bundle aggregations for state events.
bundle_aggregations=False,
results["state"], time_now
)

return HTTPStatus.OK, results
Expand Down
5 changes: 1 addition & 4 deletions synapse/rest/client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,10 +716,7 @@ async def on_GET(
results["events_after"], time_now
)
results["state"] = await self._event_serializer.serialize_events(
results["state"],
time_now,
# No need to bundle aggregations for state events.
bundle_aggregations=False,
results["state"], time_now
)

return 200, results
Expand Down
17 changes: 6 additions & 11 deletions synapse/rest/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,13 @@ async def encode_room(
The room, encoded in our response format
"""

def serialize(
events: Iterable[EventBase], bundle_aggregations: bool
) -> Awaitable[List[JsonDict]]:
def serialize(events: Iterable[EventBase]) -> Awaitable[List[JsonDict]]:
return self._event_serializer.serialize_events(
events,
time_now=time_now,
bundle_aggregations=bundle_aggregations,
# Don't bother to bundle aggregations if the timeline is unlimited,
# as clients will have all the necessary information.
bundle_aggregations=room.timeline.limited,
token_id=token_id,
event_format=event_formatter,
only_event_fields=only_fields,
Expand All @@ -544,13 +544,8 @@ def serialize(
event.room_id,
)

# No need to bundle aggregations for state events.
serialized_state = await serialize(state_events, bundle_aggregations=False)
# Don't bother to bundle aggregations if the timeline is unlimited, as
# clients will have all the necessary information.
serialized_timeline = await serialize(
timeline_events, bundle_aggregations=room.timeline.limited
)
serialized_state = await serialize(state_events)
serialized_timeline = await serialize(timeline_events)

account_data = room.account_data

Expand Down