Fix background update for sliding sync (find previous membership) (v1)#17631
Conversation
This reverts commit ab414f2.
| """ | ||
| SELECT m.event_id, m.membership | ||
| FROM event_auth AS a | ||
| INNER JOIN room_memberships AS m ON (a.auth_id = m.event_id) |
There was a problem hiding this comment.
For context on why this doesn't work, @erikjohnston ran this on matrix.org and found a leave membership where the event_auth only has two events that we don't have at all. The low number of event_auth is suspicious and really strange that we don't have the events at all. Even checking the PDU event JSON of the leave event shows it having two auth events.
According to the room_memberships table, they were previously invite
Another strange thing is that the room_memberships.event_id of the invite event doesn't match one of the event_auth of the leave event (the leave event doesn't point back to the invite).
| WHERE | ||
| room_id = ? | ||
| AND user_id = ? | ||
| AND event_stream_ordering < ? |
There was a problem hiding this comment.
@erikjohnston found another snag down the line:
Turns out room_memberships.event_stream_ordering can be null here.
We need to rely on the events.stream_ordering and do a INNER JOIN events AS e USING (room_id, event_id)
Even though the events.stream_ordering also doesn't have a NOT NULL constraint, it doesn't have any rows where this is the case (SELECT event_id FROM events WHERE stream_ordering = null;). The fact it is a nullable column is a holdover from a rename of the column.
This reverts commit ab414f2.
Introduced in #17599