correctly handle None state_keys

and fix include_other_types thinko
This commit is contained in:
Matthew Hodgson 2018-03-12 01:39:06 +00:00
parent 97c0496cfa
commit fdedcd1f4d

View File

@ -276,15 +276,23 @@ class StateGroupWorkerStore(SQLBaseStore):
key = (typ, state_key) key = (typ, state_key)
results[group][key] = event_id results[group][key] = event_id
else: else:
where_args = []
if types is not None: if types is not None:
where_clause = "AND (%s" % ( where_clause = "AND ("
" OR ".join(["(type = ? AND state_key = ?)"] * len(types)), for typ in types:
) if typ[1] is None:
where_clause += "(type = ?) OR "
where_args.extend(typ[0])
else:
where_clause += "(type = ? AND state_key = ?) OR "
where_args.extend([typ[0], typ[1]])
if include_other_types: if include_other_types:
where_clause += " OR (%s)" % ( where_clause += "(%s) OR " % (
" AND ".join(["type <> ?"] * len(types)), " AND ".join(["type <> ?"] * len(types)),
) )
where_clause += ")" where_args.extend(t for (t, _) in types)
where_clause += "0)" # 0 to terminate the last OR
else: else:
where_clause = "" where_clause = ""
@ -301,9 +309,7 @@ class StateGroupWorkerStore(SQLBaseStore):
# after we finish deduping state, which requires this func) # after we finish deduping state, which requires this func)
args = [next_group] args = [next_group]
if types: if types:
args.extend(i for typ in types for i in typ) args.extend(where_args)
if include_other_types:
args.extend(typ for (typ, _) in types)
txn.execute( txn.execute(
"SELECT type, state_key, event_id FROM state_groups_state" "SELECT type, state_key, event_id FROM state_groups_state"
@ -507,12 +513,12 @@ class StateGroupWorkerStore(SQLBaseStore):
def include(typ, state_key): def include(typ, state_key):
valid_state_keys = type_to_key.get(typ, sentinel) valid_state_keys = type_to_key.get(typ, sentinel)
if valid_state_keys is sentinel: if valid_state_keys is sentinel:
return False return include_other_types
if valid_state_keys is None: if valid_state_keys is None:
return True return True
if state_key in valid_state_keys: if state_key in valid_state_keys:
return True return True
return include_other_types return False
got_all = is_all or not missing_types got_all = is_all or not missing_types