summary refs log tree commit diff
path: root/synapse/storage/events_worker.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-05-30 15:26:55 +0100
committerErik Johnston <erik@matrix.org>2019-05-30 15:26:55 +0100
commit5ac75fc9a2d80ddf2974d281c381f82515606403 (patch)
treec37cdd6f3224273c6c8780e429163bd2148de9b6 /synapse/storage/events_worker.py
parentMove deletion from table inside txn (diff)
downloadsynapse-5ac75fc9a2d80ddf2974d281c381f82515606403.tar.xz
Join against events to use its room_id index
Diffstat (limited to 'synapse/storage/events_worker.py')
-rw-r--r--synapse/storage/events_worker.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/synapse/storage/events_worker.py b/synapse/storage/events_worker.py
index b56c83e460..1782428048 100644
--- a/synapse/storage/events_worker.py
+++ b/synapse/storage/events_worker.py
@@ -618,7 +618,12 @@ class EventsWorkerStore(SQLBaseStore):
         """
         See get_total_state_event_counts.
         """
-        sql = "SELECT COUNT(*) FROM state_events WHERE room_id=?"
+        # We join against the events table as that has an index on room_id
+        sql = """
+            SELECT COUNT(*) FROM state_events
+            INNER JOIN events USING (room_id, event_id)
+            WHERE room_id=?
+        """
         txn.execute(sql, (room_id,))
         row = txn.fetchone()
         return row[0] if row else 0