-
Notifications
You must be signed in to change notification settings - Fork 203
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
Fix background update for sliding sync (find previous membership) (v1) #17631
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Store sliding sync per-connection state in the database. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1961,27 +1961,33 @@ def _find_memberships_to_update_txn( | |
return 0 | ||
|
||
def _find_previous_membership_txn( | ||
txn: LoggingTransaction, event_id: str, user_id: str | ||
txn: LoggingTransaction, room_id: str, user_id: str, stream_ordering: int | ||
) -> Tuple[str, str]: | ||
# Find the previous invite/knock event before the leave event. This | ||
# is done by looking at the auth events of the invite/knock and | ||
# finding the corresponding membership event. | ||
# Find the previous invite/knock event before the leave event | ||
txn.execute( | ||
""" | ||
SELECT m.event_id, m.membership | ||
FROM event_auth AS a | ||
INNER JOIN room_memberships AS m ON (a.auth_id = m.event_id) | ||
WHERE a.event_id = ? AND m.user_id = ? | ||
SELECT event_id, membership | ||
FROM room_memberships | ||
WHERE | ||
room_id = ? | ||
AND user_id = ? | ||
AND event_stream_ordering < ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @erikjohnston found another snag down the line: Turns out We need to rely on the Even though the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in #17632 |
||
ORDER BY event_stream_ordering DESC | ||
LIMIT 1 | ||
""", | ||
(event_id, user_id), | ||
( | ||
room_id, | ||
user_id, | ||
stream_ordering, | ||
), | ||
) | ||
row = txn.fetchone() | ||
|
||
# We should see a corresponding previous invite/knock event | ||
assert row is not None | ||
previous_event_id, membership = row | ||
event_id, membership = row | ||
|
||
return previous_event_id, membership | ||
return event_id, membership | ||
|
||
# Map from (room_id, user_id) to ... | ||
to_insert_membership_snapshots: Dict[ | ||
|
@@ -2097,8 +2103,9 @@ def _find_previous_membership_txn( | |
await self.db_pool.runInteraction( | ||
"sliding_sync_membership_snapshots_bg_update._find_previous_membership", | ||
_find_previous_membership_txn, | ||
membership_event_id, | ||
room_id, | ||
user_id, | ||
membership_event_stream_ordering, | ||
) | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context on why this doesn't work, @erikjohnston ran this on
matrix.org
and found aleave
membership where theevent_auth
only has two events that we don't have at all. The low number ofevent_auth
is suspicious and really strange that we don't have the events at all. Even checking the PDU event JSON of theleave
event shows it having two auth events.According to the
room_memberships
table, they were previouslyinvite
Another strange thing is that the
room_memberships.event_id
of theinvite
event doesn't match one of theevent_auth
of theleave
event (theleave
event doesn't point back to theinvite
).