summary refs log tree commit diff
path: root/synapse/storage/state.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-04-30 16:16:53 +0100
committerErik Johnston <erik@matrix.org>2015-04-30 16:16:53 +0100
commit3c4c2297887b973c012ff61a731b3bf6178d8d26 (patch)
treea4c20e7f3ab457a6d81fce05956d6f65d18e18d9 /synapse/storage/state.py
parentSYN-367: Use upsert rather than insert_or_replace (diff)
downloadsynapse-3c4c2297887b973c012ff61a731b3bf6178d8d26.tar.xz
Don't use sub queries, it makes postgres sad
Diffstat (limited to '')
-rw-r--r--synapse/storage/state.py16
1 files changed, 5 insertions, 11 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index c282fcf7c1..95bc15c0dc 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -128,18 +128,12 @@ class StateStore(SQLBaseStore):
 
     @defer.inlineCallbacks
     def get_current_state(self, room_id, event_type=None, state_key=""):
-        del_sql = (
-            "SELECT event_id FROM redactions WHERE redacts = e.event_id "
-            "LIMIT 1"
-        )
-
         sql = (
-            "SELECT e.*, (%(redacted)s) AS redacted FROM events as e "
-            "INNER JOIN current_state_events as c ON e.event_id = c.event_id "
-            "WHERE c.room_id = ? "
-        ) % {
-            "redacted": del_sql,
-        }
+            "SELECT e.*, r.event_id FROM events as e"
+            " LEFT JOIN redactions as r ON r.redacts = e.event_id"
+            " INNER JOIN current_state_events as c ON e.event_id = c.event_id"
+            " WHERE c.room_id = ? "
+        )
 
         if event_type and state_key is not None:
             sql += " AND c.type = ? AND c.state_key = ? "