From d844afdc2970f772589b09e615c757d25645fda9 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 29 Aug 2024 19:16:39 +0100 Subject: [PATCH] Fix background update for sliding sync (find previous membership) (#17632) This reverts commit https://github.com/element-hq/synapse/commit/ab414f2ab8a294fbffb417003eeea0f14bbd6588. Introduced in https://github.com/element-hq/synapse/pull/17512 --- changelog.d/17632.misc | 1 + synapse/storage/databases/main/events_bg_updates.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelog.d/17632.misc diff --git a/changelog.d/17632.misc b/changelog.d/17632.misc new file mode 100644 index 0000000000..756918e2b2 --- /dev/null +++ b/changelog.d/17632.misc @@ -0,0 +1 @@ +Pre-populate room data used in experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint for quick filtering/sorting. diff --git a/synapse/storage/databases/main/events_bg_updates.py b/synapse/storage/databases/main/events_bg_updates.py index 3160e12bb3..b86f873eba 100644 --- a/synapse/storage/databases/main/events_bg_updates.py +++ b/synapse/storage/databases/main/events_bg_updates.py @@ -1967,12 +1967,13 @@ class EventsBackgroundUpdatesStore(StreamWorkerStore, StateDeltasStore, SQLBaseS txn.execute( """ SELECT event_id, membership - FROM room_memberships + FROM room_memberships AS m + INNER JOIN events AS e USING (room_id, event_id) WHERE room_id = ? - AND user_id = ? - AND event_stream_ordering < ? - ORDER BY event_stream_ordering DESC + AND m.user_id = ? + AND e.stream_ordering < ? + ORDER BY e.stream_ordering DESC LIMIT 1 """, (