Skip to content

Commit

Permalink
Handle wildcard type filters properly
Browse files Browse the repository at this point in the history
  • Loading branch information
thebalaa committed Dec 20, 2023
1 parent 742bae3 commit b428032
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions synapse/storage/databases/main/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b428032

Please sign in to comment.