Skip to content

Commit

Permalink
Fix using the correct room list after #17479 merged
Browse files Browse the repository at this point in the history
See #17489 (comment)

Fixes after #17479 merged
  • Loading branch information
MadLittleMods committed Jul 30, 2024
1 parent a4127e1 commit 8e8341d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
25 changes: 14 additions & 11 deletions synapse/handlers/sliding_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,7 @@ async def current_sync_for_user(

# Assemble sliding window lists
lists: Dict[str, SlidingSyncResult.SlidingWindowList] = {}
# Keep track of the rooms that we're going to display and need to fetch more
# info about
# Keep track of the rooms that we can display and need to fetch more info about
relevant_room_map: Dict[str, RoomSyncConfig] = {}
if has_lists and sync_config.lists is not None:
sync_room_map = await self.filter_rooms_relevant_for_sync(
Expand Down Expand Up @@ -623,6 +622,8 @@ async def current_sync_for_user(

# Filter out rooms that haven't received updates and we've sent down
# previously.
# Keep track of the rooms that we're going to display and need to fetch more info about
relevant_rooms_to_send_map = relevant_room_map
if from_token:
rooms_should_send = set()

Expand Down Expand Up @@ -660,7 +661,7 @@ async def current_sync_for_user(
relevant_room_map.keys(), from_token.stream_token.room_key
)
rooms_should_send.update(rooms_that_have_updates)
relevant_room_map = {
relevant_rooms_to_send_map = {
room_id: room_sync_config
for room_id, room_sync_config in relevant_room_map.items()
if room_id in rooms_should_send
Expand All @@ -672,7 +673,7 @@ async def handle_room(room_id: str) -> None:
room_sync_result = await self.get_room_sync_data(
sync_config=sync_config,
room_id=room_id,
room_sync_config=relevant_room_map[room_id],
room_sync_config=relevant_rooms_to_send_map[room_id],
room_membership_for_user_at_to_token=room_membership_for_user_map[
room_id
],
Expand All @@ -684,17 +685,19 @@ async def handle_room(room_id: str) -> None:
if room_sync_result or not from_token:
rooms[room_id] = room_sync_result

if relevant_room_map:
if relevant_rooms_to_send_map:
with start_active_span("sliding_sync.generate_room_entries"):
await concurrently_execute(handle_room, relevant_room_map, 10)
await concurrently_execute(handle_room, relevant_rooms_to_send_map, 10)

extensions = await self.get_extensions_response(
sync_config=sync_config,
actual_lists=lists,
# TODO: Once https://github.com/element-hq/synapse/pull/17479 merges, this
# will need to be updated to make sure it includes everything before the
# pre-filter on `relevant_room_map`.
actual_room_ids=set(rooms.keys()),
# We're purposely using `relevant_room_map` instead of
# `relevant_rooms_to_send_map` here. This needs to be all room_ids we could
# send regardless of whether they have an event update or not. The
# extensions care about more than just normal events in the rooms (like
# account data, read receipts, typing indicators, to-device messages, etc).
actual_room_ids=set(relevant_room_map.keys()),
actual_room_response_map=rooms,
from_token=from_token,
to_token=to_token,
Expand All @@ -704,7 +707,7 @@ async def handle_room(room_id: str) -> None:
connection_position = await self.connection_store.record_rooms(
sync_config=sync_config,
from_token=from_token,
sent_room_ids=relevant_room_map.keys(),
sent_room_ids=relevant_rooms_to_send_map.keys(),
# TODO: We need to calculate which rooms have had updates since the `from_token` but were not included in the `sent_room_ids`
unsent_room_ids=[],
)
Expand Down
20 changes: 2 additions & 18 deletions tests/rest/client/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6657,15 +6657,7 @@ def test_receipts_incremental_sync(self) -> None:
exact=True,
)
# No events in the timeline since they were sent before the `from_token`
self.assertIncludes(
{
event["event_id"]
for event in response_body["rooms"][room_id1].get("timeline", [])
},
set(),
exact=True,
message=str(response_body["rooms"][room_id1]),
)
self.assertNotIn(room_id1, response_body["rooms"])

# Check room3:
#
Expand Down Expand Up @@ -6694,15 +6686,7 @@ def test_receipts_incremental_sync(self) -> None:
exact=True,
)
# No events in the timeline since they were sent before the `from_token`
self.assertIncludes(
{
event["event_id"]
for event in response_body["rooms"][room_id3].get("timeline", [])
},
set(),
exact=True,
message=str(response_body["rooms"][room_id3]),
)
self.assertNotIn(room_id3, response_body["rooms"])

def test_receipts_incremental_sync_all_live_receipts(self) -> None:
"""
Expand Down

0 comments on commit 8e8341d

Please sign in to comment.