From b428032f23dd515f7cac2921913e9f802c13d7bb Mon Sep 17 00:00:00 2001 From: Mo Balaa Date: Wed, 20 Dec 2023 16:53:32 -0600 Subject: [PATCH] Handle wildcard type filters properly --- synapse/storage/databases/main/stream.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/synapse/storage/databases/main/stream.py b/synapse/storage/databases/main/stream.py index 1b2a65bed2b..39287713507 100644 --- a/synapse/storage/databases/main/stream.py +++ b/synapse/storage/databases/main/stream.py @@ -398,14 +398,25 @@ def filter_to_clause(event_filter: Optional[Filter]) -> Tuple[str, List[str]]: clauses = [] args = [] + # Handle event types with potential wildcard characters if event_filter.types: - clauses.append( - "(%s)" % " OR ".join("event.type = ?" for _ in event_filter.types) - ) - args.extend(event_filter.types) + type_clauses = [] + for typ in event_filter.types: + if '*' in typ: + type_clauses.append("event.type LIKE ?") + typ = typ.replace('*', '%') # Replace * with % for SQL LIKE pattern + else: + type_clauses.append("event.type = ?") + args.append(typ) + clauses.append("(%s)" % " OR ".join(type_clauses)) + # Handle event types to exclude with potential wildcard characters for typ in event_filter.not_types: - clauses.append("event.type != ?") + if '*' in typ: + clauses.append("event.type NOT LIKE ?") + typ = typ.replace('*', '%') + else: + clauses.append("event.type != ?") args.append(typ) if event_filter.senders: