-
Notifications
You must be signed in to change notification settings - Fork 564
Fix background update for sliding sync (find previous membership) (v1) #17631
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
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 < ? | ||
|
Contributor
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
Contributor
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, | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.organd found aleavemembership where theevent_authonly has two events that we don't have at all. The low number ofevent_authis suspicious and really strange that we don't have the events at all. Even checking the PDU event JSON of theleaveevent shows it having two auth events.According to the
room_membershipstable, they were previouslyinviteAnother strange thing is that the
room_memberships.event_idof theinviteevent doesn't match one of theevent_authof theleaveevent (theleaveevent doesn't point back to theinvite).