summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorMo Balaa <thebalaa@users.noreply.github.com>2024-01-22 04:46:30 -0600
committerGitHub <noreply@github.com>2024-01-22 10:46:30 +0000
commitb99f6db0396629187b7c7e0e869e8ecc082154a5 (patch)
tree5dbd55692d832ef39c85d7267f79d259b8218193 /synapse/storage
parentBump actions/cache from 3 to 4 (#16832) (diff)
downloadsynapse-b99f6db0396629187b7c7e0e869e8ecc082154a5.tar.xz
Handle wildcard type filters properly (#14984)
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/databases/main/stream.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/synapse/storage/databases/main/stream.py b/synapse/storage/databases/main/stream.py
index aeeb74b46d..9a2940d7a1 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: