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

Commit cd3dd44

Browse files
committed
Include the bundled aggregations in the sync response cache.
1 parent 2fa075c commit cd3dd44

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

changelog.d/11659.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Include the bundled aggregations in the `/sync` response.

synapse/handlers/sync.py

+10
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class TimelineBatch:
102102
prev_batch: StreamToken
103103
events: List[EventBase]
104104
limited: bool
105+
# A mapping of event ID to the bundled aggregations for the above events.
106+
# This is only calculated if limited is true.
107+
bundled_aggregations: Optional[Dict[str, Dict[str, Any]]] = None
105108

106109
def __bool__(self) -> bool:
107110
"""Make the result appear empty if there are no updates. This is used
@@ -634,10 +637,17 @@ async def _load_filtered_recents(
634637

635638
prev_batch_token = now_token.copy_and_replace("room_key", room_key)
636639

640+
# Don't bother to bundle aggregations if the timeline is unlimited,
641+
# as clients will have all the necessary information.
642+
bundled_aggregations = None
643+
if limited:
644+
bundled_aggregations = await self.store.get_bundled_aggregations(recents)
645+
637646
return TimelineBatch(
638647
events=recents,
639648
prev_batch=prev_batch_token,
640649
limited=limited or newly_joined_room,
650+
bundled_aggregations=bundled_aggregations,
641651
)
642652

643653
async def get_state_after_event(

synapse/rest/client/sync.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -554,20 +554,9 @@ def serialize(
554554
)
555555

556556
serialized_state = serialize(state_events)
557-
# Don't bother to bundle aggregations if the timeline is unlimited,
558-
# as clients will have all the necessary information.
559-
# bundle_aggregations=room.timeline.limited,
560-
#
561-
# richvdh 2021-12-15: disable this temporarily as it has too high an
562-
# overhead for initialsyncs. We need to figure out a way that the
563-
# bundling can be done *before* the events are stored in the
564-
# SyncResponseCache so that this part can be synchronous.
565-
#
566-
# Ensure to re-enable the test at tests/rest/client/test_relations.py::RelationsTestCase.test_bundled_aggregations.
567-
# if room.timeline.limited:
568-
# aggregations = await self.store.get_bundled_aggregations(timeline_events)
569-
aggregations = None
570-
serialized_timeline = serialize(timeline_events, aggregations)
557+
serialized_timeline = serialize(
558+
timeline_events, room.timeline.bundled_aggregations
559+
)
571560

572561
account_data = room.account_data
573562

tests/rest/client/test_relations.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,11 @@ def _find_and_assert_event(events):
577577
assert_bundle(channel.json_body["event"]["unsigned"].get("m.relations"))
578578

579579
# Request sync.
580-
# channel = self.make_request("GET", "/sync", access_token=self.user_token)
581-
# self.assertEquals(200, channel.code, channel.json_body)
582-
# room_timeline = channel.json_body["rooms"]["join"][self.room]["timeline"]
583-
# self.assertTrue(room_timeline["limited"])
584-
# _find_and_assert_event(room_timeline["events"])
580+
channel = self.make_request("GET", "/sync", access_token=self.user_token)
581+
self.assertEquals(200, channel.code, channel.json_body)
582+
room_timeline = channel.json_body["rooms"]["join"][self.room]["timeline"]
583+
self.assertTrue(room_timeline["limited"])
584+
_find_and_assert_event(room_timeline["events"])
585585

586586
# Note that /relations is tested separately in test_aggregation_get_event_for_thread
587587
# since it needs different data configured.

0 commit comments

Comments
 (0)