summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorJason Robinson <jasonr@matrix.org>2021-01-11 23:49:58 +0200
committerJason Robinson <jasonr@matrix.org>2021-01-11 23:49:58 +0200
commit49c619a9a2203da61f496fe6e3ae308be87efda8 (patch)
tree5ee1d0f595a1cd9f2f0750e3f2a94206dc294d17 /synapse/storage
parentAddress pr feedback (diff)
downloadsynapse-49c619a9a2203da61f496fe6e3ae308be87efda8.tar.xz
Simplify delete_forward_extremities_for_room_txn SQL
As per feedback.

Signed-off-by: Jason Robinson <jasonr@matrix.org>
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/databases/main/events_forward_extremities.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/synapse/storage/databases/main/events_forward_extremities.py b/synapse/storage/databases/main/events_forward_extremities.py
index e6c2d6e122..c7ec08469d 100644
--- a/synapse/storage/databases/main/events_forward_extremities.py
+++ b/synapse/storage/databases/main/events_forward_extremities.py
@@ -35,17 +35,11 @@ class EventForwardExtremitiesStore(SQLBaseStore):
         def delete_forward_extremities_for_room_txn(txn):
             # First we need to get the event_id to not delete
             sql = """
-                SELECT
-                    last_value(event_id) OVER w AS event_id
-                FROM event_forward_extremities
-                    NATURAL JOIN events
+                SELECT event_id FROM event_forward_extremities
+                INNER JOIN events USING (room_id, event_id)
                 WHERE room_id = ?
-                    WINDOW w AS (
-                        PARTITION BY room_id
-                        ORDER BY stream_ordering 
-                        range between unbounded preceding and unbounded following
-                    )
-                ORDER BY stream_ordering
+                ORDER BY stream_ordering DESC
+                LIMIT 1
             """
             txn.execute(sql, (room_id,))
             rows = txn.fetchall()