Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sliding sync: don't port left rooms in sliding sync tables background update #17699

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions synapse/storage/databases/main/events_bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1927,10 +1927,11 @@ def _find_memberships_to_update_txn(
LEFT JOIN rooms AS r ON (c.room_id = r.room_id)
WHERE (c.room_id, c.user_id) > (?, ?)
AND (m.user_id IS NULL OR c.event_id != m.membership_event_id)
AND (c.membership != ? OR c.user_id != e.sender)
ORDER BY c.room_id ASC, c.user_id ASC
LIMIT ?
""",
(last_room_id, last_user_id, batch_size),
(last_room_id, last_user_id, Membership.LEAVE, batch_size),
)
elif last_event_stream_ordering is not None:
# It's important to sort by `event_stream_ordering` *ascending* (oldest to
Expand Down Expand Up @@ -1961,10 +1962,11 @@ def _find_memberships_to_update_txn(
LEFT JOIN rooms AS r ON (c.room_id = r.room_id)
WHERE c.event_stream_ordering > ?
AND (m.user_id IS NULL OR c.event_id != m.membership_event_id)
AND (c.membership != ? OR c.user_id != e.sender)
ORDER BY c.event_stream_ordering ASC
LIMIT ?
""",
(last_event_stream_ordering, batch_size),
(last_event_stream_ordering, Membership.LEAVE, batch_size),
)
else:
raise Exception("last_event_stream_ordering should not be None")
Expand Down
73 changes: 8 additions & 65 deletions tests/storage/test_sliding_sync_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3507,10 +3507,6 @@ def test_membership_snapshots_background_update_local_invite(self) -> None:
(room_id_no_info, user1_id),
(room_id_with_info, user1_id),
(space_room_id, user1_id),
# The leave memberships for user2
(room_id_no_info, user2_id),
(room_id_with_info, user2_id),
(space_room_id, user2_id),
},
exact=True,
)
Expand Down Expand Up @@ -3892,16 +3888,12 @@ def test_membership_snapshots_background_update_remote_invite_rejections_and_ret

# Reject the remote invites.
# Also try retracting a remote invite.
room_id_unknown_state_leave_event_response = self.helper.leave(
room_id_unknown_state, user1_id, tok=user1_tok
)
self.helper.leave(room_id_unknown_state, user1_id, tok=user1_tok)
room_id_no_info_leave_event = self._retract_remote_invite_for_user(
user_id=user1_id,
remote_room_id=room_id_no_info,
)
room_id_with_info_leave_event_response = self.helper.leave(
room_id_with_info, user1_id, tok=user1_tok
)
self.helper.leave(room_id_with_info, user1_id, tok=user1_tok)
space_room_id_leave_event = self._retract_remote_invite_for_user(
user_id=user1_id,
remote_room_id=space_room_id,
Expand Down Expand Up @@ -3956,37 +3948,11 @@ def test_membership_snapshots_background_update_remote_invite_rejections_and_ret
set(sliding_sync_membership_snapshots_results.keys()),
{
# The invite memberships for user1
(room_id_unknown_state, user1_id),
(room_id_no_info, user1_id),
(room_id_with_info, user1_id),
(space_room_id, user1_id),
},
exact=True,
)
self.assertEqual(
sliding_sync_membership_snapshots_results.get(
(room_id_unknown_state, user1_id)
),
_SlidingSyncMembershipSnapshotResult(
room_id=room_id_unknown_state,
user_id=user1_id,
sender=user1_id,
membership_event_id=room_id_unknown_state_leave_event_response[
"event_id"
],
membership=Membership.LEAVE,
event_stream_ordering=self.get_success(
self.store.get_position_for_event(
room_id_unknown_state_leave_event_response["event_id"]
)
).stream,
has_known_state=False,
room_type=None,
room_name=None,
is_encrypted=False,
tombstone_successor_room_id=None,
),
)
self.assertEqual(
sliding_sync_membership_snapshots_results.get((room_id_no_info, user1_id)),
_SlidingSyncMembershipSnapshotResult(
Expand All @@ -4003,28 +3969,6 @@ def test_membership_snapshots_background_update_remote_invite_rejections_and_ret
tombstone_successor_room_id=None,
),
)
self.assertEqual(
sliding_sync_membership_snapshots_results.get(
(room_id_with_info, user1_id)
),
_SlidingSyncMembershipSnapshotResult(
room_id=room_id_with_info,
user_id=user1_id,
sender=user1_id,
membership_event_id=room_id_with_info_leave_event_response["event_id"],
membership=Membership.LEAVE,
event_stream_ordering=self.get_success(
self.store.get_position_for_event(
room_id_with_info_leave_event_response["event_id"]
)
).stream,
has_known_state=True,
room_type=None,
room_name="my super duper room",
is_encrypted=True,
tombstone_successor_room_id=None,
),
)
self.assertEqual(
sliding_sync_membership_snapshots_results.get((space_room_id, user1_id)),
_SlidingSyncMembershipSnapshotResult(
Expand Down Expand Up @@ -4220,10 +4164,6 @@ def test_membership_snapshots_background_update_historical_state(
(room_id_no_info, user1_id),
(room_id_with_info, user1_id),
(space_room_id, user1_id),
# The leave memberships for user2
(room_id_no_info, user2_id),
(room_id_with_info, user2_id),
(space_room_id, user2_id),
},
exact=True,
)
Expand Down Expand Up @@ -4312,7 +4252,7 @@ def test_membership_snapshots_background_update_forgotten_missing(self) -> None:
# User1 joins the room
self.helper.join(room_id, user1_id, tok=user1_tok)
# User1 leaves the room (we have to leave in order to forget the room)
self.helper.leave(room_id, user1_id, tok=user1_tok)
self.helper.leave(room_id, user1_id, tok=user2_tok)

state_map = self.get_success(
self.storage_controllers.state.get_current_state(room_id)
Expand Down Expand Up @@ -4381,7 +4321,7 @@ def test_membership_snapshots_background_update_forgotten_missing(self) -> None:
_SlidingSyncMembershipSnapshotResult(
room_id=room_id,
user_id=user1_id,
sender=user1_id,
sender=user2_id,
membership_event_id=state_map[(EventTypes.Member, user1_id)].event_id,
membership=Membership.LEAVE,
event_stream_ordering=state_map[
Expand Down Expand Up @@ -4820,7 +4760,7 @@ def test_membership_snapshots_background_update_catch_up_membership_change(
)

# User2 leaves the room
self.helper.leave(room_id, user2_id, tok=user2_tok)
self.helper.leave(room_id, user2_id, tok=user1_tok)

# Make sure all of the background updates have finished before we start the
# catch-up. Even though it should work fine if the other background update is
Expand All @@ -4841,6 +4781,9 @@ def test_membership_snapshots_background_update_catch_up_membership_change(
keyvalues={"room_id": room_id, "user_id": user2_id},
updatevalues={
# Reset everything back to the value before user2 left the room
"sender": sliding_sync_membership_snapshots_results_before_membership_changes[
(room_id, user2_id)
].sender,
"membership": sliding_sync_membership_snapshots_results_before_membership_changes[
(room_id, user2_id)
].membership,
Expand Down
Loading