mirror of
https://github.com/element-hq/synapse.git
synced 2026-11-04 11:17:51 +00:00
Follows: #18375 This bugfix is a prerequisite for MSC4354 (Sticky Events, Experimental Feature tracking issue #19409) changes. - Add a failing test for join->join being newly_joined - Fix the join->join transition being treated as a new join (when prev_events didn't coincidentally mask the problem) Rationale: `event_edges` / `prev_events` does NOT link a membership event to its previous state. (It could even be someone else's membership!) In most real-world cases, this would generate a `prev_membership` of NULL for every normal membership change. It appears as though the author intended some kind of 'previous state' relationship, but if you fix the first branch of the `UNION` query to use `current_state_delta_stream` for this (which is the source of state transitions), then it looks very redundant with the second branch. It looks like the real reason we want to use the snapshots table is for out-of-band memberships (outlier memberships). So we continue using that for those, but ONLY for those. The `SUSPICIOUS` if block is removed because it appears to have been papering over this issue by deduplicating the spurious `NULL` -> non-null transitions, but when you remove those duplicates at the source, it causes more trouble because it doesn't know that what it's 'deduplicating' is actually the same membership transition. This means if you join, then out-of-band leave (e.g. last member on the server to leave), that room would appear in `newly_joined` on a new initial sync. (Tests did in fact catch this, too.) --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>