summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2018-03-13 18:13:44 +0000
committerMatthew Hodgson <matthew@matrix.org>2018-03-13 18:13:44 +0000
commitb2aba9e43053f9f297671fce0051bfc18a8b655a (patch)
tree8da9cb939d1263f350e46db950c54c0abf44c4f2
parentPR feedbackz (diff)
downloadsynapse-b2aba9e43053f9f297671fce0051bfc18a8b655a.tar.xz
build where_clause sanely
-rw-r--r--synapse/storage/state.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index 77259a3141..82740266bf 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -263,18 +263,16 @@ class StateGroupWorkerStore(SQLBaseStore):
                         results[group][key] = event_id
         else:
             where_args = []
+            where_clauses = []
             if types is not None:
-                where_clause = "AND ("
                 for typ in types:
                     if typ[1] is None:
-                        where_clause += "(type = ?)"
+                        where_clauses.append("(type = ?)")
                         where_args.extend(typ[0])
                     else:
-                        where_clause += "(type = ? AND state_key = ?)"
+                        where_clauses.append("(type = ? AND state_key = ?)")
                         where_args.extend([typ[0], typ[1]])
-                    if typ != types[-1]:
-                        where_clause += " OR "
-                where_clause += ")"
+                where_clause = "AND (%s)" % (" OR ".join(where_clauses))
             else:
                 where_clause = ""