summary refs log tree commit diff
path: root/synapse/storage/stream.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-04-30 18:32:03 +0100
committerErik Johnston <erik@matrix.org>2015-04-30 18:32:03 +0100
commit6ead27dddab13df042d8da4bbf64a10068358c3a (patch)
tree1faecc568a442146f22b8e71b2728ee854b4d515 /synapse/storage/stream.py
parentFix up get_current_state and get_room_name_and_aliases queries to parse event... (diff)
downloadsynapse-6ead27dddab13df042d8da4bbf64a10068358c3a.tar.xz
Add more conditions on JOINs to make postgres go a little faster.
Diffstat (limited to 'synapse/storage/stream.py')
-rw-r--r--synapse/storage/stream.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index df6de7cbcd..280d4ad605 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -149,7 +149,8 @@ class StreamStore(SQLBaseStore):
         # select all the events between from/to with a sensible limit
         sql = (
             "SELECT e.event_id, e.room_id, e.type, s.state_key, "
-            "e.stream_ordering FROM events AS e LEFT JOIN state_events as s ON "
+            "e.stream_ordering FROM events AS e "
+            "LEFT JOIN state_events as s ON "
             "e.event_id = s.event_id "
             "WHERE e.stream_ordering > ? AND e.stream_ordering <= ? "
             "ORDER BY stream_ordering ASC LIMIT %(limit)d "
@@ -214,8 +215,9 @@ class StreamStore(SQLBaseStore):
 
         current_room_membership_sql = (
             "SELECT m.room_id FROM room_memberships as m "
-            "INNER JOIN current_state_events as c ON m.event_id = c.event_id "
-            "WHERE m.user_id = ? AND m.membership = 'join'"
+            " INNER JOIN current_state_events as c"
+            " ON m.event_id = c.event_id AND c.state_key = m.user_id"
+            " WHERE m.user_id = ? AND m.membership = 'join'"
         )
 
         # We also want to get any membership events about that user, e.g.