summary refs log tree commit diff
path: root/synapse/storage/databases
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2022-05-31 13:51:49 +0100
committerGitHub <noreply@github.com>2022-05-31 13:51:49 +0100
commit5e17922ef715e3c68911955b32f42a70d6728831 (patch)
treea478beed5aa2a1291fa9deb308e655d507d31544 /synapse/storage/databases
parentRename storage classes (#12913) (diff)
downloadsynapse-5e17922ef715e3c68911955b32f42a70d6728831.tar.xz
Stop reading from `event_edges.room_id`. (#12914)
event_edges.room_id is implied by the event id, so there is no need to join on the room id.
Diffstat (limited to 'synapse/storage/databases')
-rw-r--r--synapse/storage/databases/main/event_federation.py7
-rw-r--r--synapse/storage/databases/main/events_worker.py33
2 files changed, 17 insertions, 23 deletions
diff --git a/synapse/storage/databases/main/event_federation.py b/synapse/storage/databases/main/event_federation.py
index 562dcbe94d..eec55b6478 100644
--- a/synapse/storage/databases/main/event_federation.py
+++ b/synapse/storage/databases/main/event_federation.py
@@ -1318,17 +1318,14 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas
 
         query = (
             "SELECT prev_event_id FROM event_edges "
-            "WHERE room_id = ? AND event_id = ? AND is_state = ? "
+            "WHERE event_id = ? AND NOT is_state "
             "LIMIT ?"
         )
 
         while front and len(event_results) < limit:
             new_front = set()
             for event_id in front:
-                txn.execute(
-                    query, (room_id, event_id, False, limit - len(event_results))
-                )
-
+                txn.execute(query, (event_id, limit - len(event_results)))
                 new_results = {t[0] for t in txn} - seen_events
 
                 new_front |= new_results
diff --git a/synapse/storage/databases/main/events_worker.py b/synapse/storage/databases/main/events_worker.py
index a97d7e1664..b99b107784 100644
--- a/synapse/storage/databases/main/events_worker.py
+++ b/synapse/storage/databases/main/events_worker.py
@@ -1928,6 +1928,18 @@ class EventsWorkerStore(SQLBaseStore):
                 LIMIT 1
             """
 
+            # We consider any forward extremity as the latest in the room and
+            # not a forward gap.
+            #
+            # To expand, even though there is technically a gap at the front of
+            # the room where the forward extremities are, we consider those the
+            # latest messages in the room so asking other homeservers for more
+            # is useless. The new latest messages will just be federated as
+            # usual.
+            txn.execute(forward_extremity_query, (event.room_id, event.event_id))
+            if txn.fetchone():
+                return False
+
             # Check to see whether the event in question is already referenced
             # by another event. If we don't see any edges, we're next to a
             # forward gap.
@@ -1936,8 +1948,7 @@ class EventsWorkerStore(SQLBaseStore):
                 /* Check to make sure the event referencing our event in question is not rejected */
                 LEFT JOIN rejections ON event_edges.event_id = rejections.event_id
                 WHERE
-                    event_edges.room_id = ?
-                    AND event_edges.prev_event_id = ?
+                    event_edges.prev_event_id = ?
                     /* It's not a valid edge if the event referencing our event in
                      * question is rejected.
                      */
@@ -1945,25 +1956,11 @@ class EventsWorkerStore(SQLBaseStore):
                 LIMIT 1
             """
 
-            # We consider any forward extremity as the latest in the room and
-            # not a forward gap.
-            #
-            # To expand, even though there is technically a gap at the front of
-            # the room where the forward extremities are, we consider those the
-            # latest messages in the room so asking other homeservers for more
-            # is useless. The new latest messages will just be federated as
-            # usual.
-            txn.execute(forward_extremity_query, (event.room_id, event.event_id))
-            forward_extremities = txn.fetchall()
-            if len(forward_extremities):
-                return False
-
             # If there are no forward edges to the event in question (another
             # event hasn't referenced this event in their prev_events), then we
             # assume there is a forward gap in the history.
-            txn.execute(forward_edge_query, (event.room_id, event.event_id))
-            forward_edges = txn.fetchall()
-            if not len(forward_edges):
+            txn.execute(forward_edge_query, (event.event_id,))
+            if not txn.fetchone():
                 return True
 
             return False