summary refs log tree commit diff
path: root/synapse/storage/user_directory.py
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2017-11-30 01:17:15 +0000
committerMatthew Hodgson <matthew@matrix.org>2017-11-30 01:17:15 +0000
commita4bb133b6880c6adffce5feef3681504730cd484 (patch)
tree501acc1ed6ada420470ef2bf2452aaecb659ab4e /synapse/storage/user_directory.py
parentkick the user_directory index when new users register (diff)
downloadsynapse-a4bb133b6880c6adffce5feef3681504730cd484.tar.xz
fix thinkos galore
Diffstat (limited to 'synapse/storage/user_directory.py')
-rw-r--r--synapse/storage/user_directory.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/synapse/storage/user_directory.py b/synapse/storage/user_directory.py
index 1cc73e3878..d8c9657125 100644
--- a/synapse/storage/user_directory.py
+++ b/synapse/storage/user_directory.py
@@ -640,13 +640,17 @@ class UserDirectoryStore(SQLBaseStore):
                 }
         """
 
-        include_pattern_clause = ""
+        include_pattern_join = ""
+        include_pattern_where_clause = ""
         if self.hs.config.user_directory_include_pattern:
-            include_pattern_clause = "OR d.user_id LIKE '%s'" % (
-                self.hs.config.user_directory_include_pattern
-            )
+            include_pattern_join = """
+                LEFT JOIN (
+                    SELECT user_id FROM user_directory
+                    WHERE user_id LIKE '%s'
+                ) AS ld USING (user_id)
+            """ % ( self.hs.config.user_directory_include_pattern )
 
-        logger.error("include pattern is %s" % (include_pattern))
+            include_pattern_where_clause = "OR ld.user_id IS NOT NULL"
 
         if isinstance(self.database_engine, PostgresEngine):
             full_query, exact_query, prefix_query = _parse_query_postgres(search_term)
@@ -665,6 +669,7 @@ class UserDirectoryStore(SQLBaseStore):
                     SELECT other_user_id AS user_id FROM users_who_share_rooms
                     WHERE user_id = ? AND share_private
                 ) AS s USING (user_id)
+                %s
                 WHERE
                     (s.user_id IS NOT NULL OR p.user_id IS NOT NULL %s)
                     AND vector @@ to_tsquery('english', ?)
@@ -690,7 +695,7 @@ class UserDirectoryStore(SQLBaseStore):
                     display_name IS NULL,
                     avatar_url IS NULL
                 LIMIT ?
-            """ % ( include_pattern_clause )
+            """ % ( include_pattern_join, include_pattern_where_clause )
             args = (user_id, full_query, exact_query, prefix_query, limit + 1,)
         elif isinstance(self.database_engine, Sqlite3Engine):
             search_query = _parse_query_sqlite(search_term)
@@ -704,6 +709,7 @@ class UserDirectoryStore(SQLBaseStore):
                     SELECT other_user_id AS user_id FROM users_who_share_rooms
                     WHERE user_id = ? AND share_private
                 ) AS s USING (user_id)
+                %s
                 WHERE
                     (s.user_id IS NOT NULL OR p.user_id IS NOT NULL %s)
                     AND value MATCH ?
@@ -712,7 +718,7 @@ class UserDirectoryStore(SQLBaseStore):
                     display_name IS NULL,
                     avatar_url IS NULL
                 LIMIT ?
-            """ % ( include_pattern_clause )
+            """ % ( include_pattern_join, include_pattern_where_clause )
             args = (user_id, search_query, limit + 1)
         else:
             # This should be unreachable.