summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2018-03-13 19:45:36 +0000
committerMatthew Hodgson <matthew@matrix.org>2018-03-13 19:46:04 +0000
commit865377a70d9d7db27b89348d2ebbd394f701c490 (patch)
tree485ba78a450901c31cfbd3f3b09bbdcd975fa90c /synapse
parentbuild where_clause sanely (diff)
downloadsynapse-865377a70d9d7db27b89348d2ebbd394f701c490.tar.xz
disable optimisation for searching for state groups
when type filter includes wildcards on state_key
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/state.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/synapse/storage/state.py b/synapse/storage/state.py
index 82740266bf..39f73afaa2 100644
--- a/synapse/storage/state.py
+++ b/synapse/storage/state.py
@@ -264,11 +264,13 @@ class StateGroupWorkerStore(SQLBaseStore):
         else:
             where_args = []
             where_clauses = []
+            wildcard_types = False
             if types is not None:
                 for typ in types:
                     if typ[1] is None:
                         where_clauses.append("(type = ?)")
                         where_args.extend(typ[0])
+                        wildcard_types = True
                     else:
                         where_clauses.append("(type = ? AND state_key = ?)")
                         where_args.extend([typ[0], typ[1]])
@@ -302,9 +304,17 @@ class StateGroupWorkerStore(SQLBaseStore):
                         if (typ, state_key) not in results[group]
                     )
 
-                    # If the lengths match then we must have all the types,
-                    # so no need to go walk further down the tree.
-                    if types is not None and len(results[group]) == len(types):
+                    # If the number of entries inthe (type,state_key)->event_id dict
+                    # matches the number of (type,state_keys) types we were searching
+                    # for, then we must have found them all, so no need to go walk
+                    # further down the tree... UNLESS our types filter contained
+                    # wildcards (i.e. Nones) in which case we have to do an exhaustive
+                    # search
+                    if (
+                        types is not None and
+                        not wildcard_types and
+                        len(results[group]) == len(types)
+                    ):
                         break
 
                     next_group = self._simple_select_one_onecol_txn(