Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix get_filtered_current_state_ids()'s usage of filtered_types #3792

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3792.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix get_filtered_current_state_ids()s usage of filtered_type
13 changes: 6 additions & 7 deletions synapse/storage/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _get_current_state_ids_txn(txn):
_get_current_state_ids_txn,
)

# FIXME: how should this be cached?
# FIXME: we should cache this if it turns out to be hit too often by /members
def get_filtered_current_state_ids(self, room_id, types, filtered_types=None):
"""Get the current state event of a given type for a room based on the
current_state_events table. This may not be as up-to-date as the result
Expand All @@ -175,6 +175,7 @@ def _get_filtered_current_state_ids_txn(txn):
# Turns out that postgres doesn't like doing a list of OR's and
# is about 1000x slower, so we just issue a query for each specific
# type seperately.
additional_args = ()
if types:
clause_to_args = [
(
Expand All @@ -189,19 +190,17 @@ def _get_filtered_current_state_ids_txn(txn):

if include_other_types:
unique_types = set(filtered_types)
clause_to_args.append(
(
"AND type <> ? " * len(unique_types),
list(unique_types)
)
)
sql += " AND type <> ? " * len(unique_types)
additional_args = list(unique_types)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not obvious to me that this needs copying: why not just additional_args = unique_types ?

else:
# If types is None we fetch all the state, and so just use an
# empty where clause with no extra args.
clause_to_args = [("", [])]

for where_clause, where_args in clause_to_args:
args = [room_id]
args.extend(where_args)
args.extend(additional_args)
txn.execute(sql % (where_clause,), args)
for row in txn:
typ, state_key, event_id = row
Expand Down