Skip to content

Commit

Permalink
Sliding Sync: Batch up fetching receipts (#17589)
Browse files Browse the repository at this point in the history
This is to make initial sliding sync a bit faster
  • Loading branch information
erikjohnston authored Aug 20, 2024
1 parent 8b8d74d commit 950ba84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.d/17589.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correctly track read receipts that should be sent down in experimental sliding sync.
30 changes: 16 additions & 14 deletions synapse/handlers/sliding_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2858,6 +2858,7 @@ async def get_account_data_extension_response(
account_data_by_room_map=account_data_by_room_map,
)

@trace
async def get_receipts_extension_response(
self,
sync_config: SlidingSyncConfig,
Expand Down Expand Up @@ -2966,24 +2967,25 @@ async def get_receipts_extension_response(
# from that room but we only want to include receipts for events
# in the timeline to avoid bloating and blowing up the sync response
# as the number of users in the room increases. (this behavior is part of the spec)
for room_id in initial_rooms:
room_result = actual_room_response_map.get(room_id)
if room_result is None:
continue

relevant_event_ids = [
event.event_id for event in room_result.timeline_events
]

# TODO: In the future, it would be good to fetch less receipts
# out of the database in the first place but we would need to
# add a new `event_id` index to `receipts_linearized`.
initial_receipts = await self.store.get_linearized_receipts_for_room(
room_id=room_id,
initial_rooms = {
room_id
for room_id in initial_rooms
if room_id in actual_room_response_map
}
if initial_rooms:
initial_receipts = await self.store.get_linearized_receipts_for_rooms(
room_ids=initial_rooms,
to_key=to_token.receipt_key,
)

for receipt in initial_receipts:
relevant_event_ids = {
event.event_id
for event in actual_room_response_map[
receipt["room_id"]
].timeline_events
}

content = {
event_id: content_value
for event_id, content_value in receipt["content"].items()
Expand Down

0 comments on commit 950ba84

Please sign in to comment.