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

Commit d16f557

Browse files
authored
Merge pull request #5220 from matrix-org/erikj/dont_bundle_live_events
Don't bundle aggregations with events in /sync or /events or state queries
2 parents 8c41c04 + 4cb577c commit d16f557

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

changelog.d/5220.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add experimental support for relations (aka reactions and edits).

synapse/events/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,13 @@ def __init__(self, hs):
330330
)
331331

332332
@defer.inlineCallbacks
333-
def serialize_event(self, event, time_now, **kwargs):
333+
def serialize_event(self, event, time_now, bundle_aggregations=True, **kwargs):
334334
"""Serializes a single event.
335335
336336
Args:
337337
event (EventBase)
338338
time_now (int): The current time in milliseconds
339+
bundle_aggregations (bool): Whether to bundle in related events
339340
**kwargs: Arguments to pass to `serialize_event`
340341
341342
Returns:
@@ -350,7 +351,7 @@ def serialize_event(self, event, time_now, **kwargs):
350351

351352
# If MSC1849 is enabled then we need to look if thre are any relations
352353
# we need to bundle in with the event
353-
if self.experimental_msc1849_support_enabled:
354+
if self.experimental_msc1849_support_enabled and bundle_aggregations:
354355
annotations = yield self.store.get_aggregation_groups_for_event(
355356
event_id,
356357
)

synapse/handlers/events.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def get_stream(self, auth_user_id, pagin_config, timeout=0,
122122

123123
chunks = yield self._event_serializer.serialize_events(
124124
events, time_now, as_client_event=as_client_event,
125+
# We don't bundle "live" events, as otherwise clients
126+
# will end up double counting annotations.
127+
bundle_aggregations=False,
125128
)
126129

127130
chunk = {

synapse/handlers/message.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def get_state_events(
166166
now = self.clock.time_msec()
167167
events = yield self._event_serializer.serialize_events(
168168
room_state.values(), now,
169+
# We don't bother bundling aggregations in when asked for state
170+
# events, as clients won't use them.
171+
bundle_aggregations=False,
169172
)
170173
defer.returnValue(events)
171174

synapse/rest/client/v2_alpha/sync.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ def encode_room(
358358
def serialize(events):
359359
return self._event_serializer.serialize_events(
360360
events, time_now=time_now,
361+
# We don't bundle "live" events, as otherwise clients
362+
# will end up double counting annotations.
363+
bundle_aggregations=False,
361364
token_id=token_id,
362365
event_format=event_formatter,
363366
only_event_fields=only_fields,

0 commit comments

Comments
 (0)