diff options
author | Richard van der Hoff <github@rvanderhoff.org.uk> | 2018-01-27 22:58:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-27 22:58:24 +0100 |
commit | 4c65b98e4add3e5969057a2f1b97568d554ca7b9 (patch) | |
tree | d7feb1582da4e349c832f1dca0934ae435462dc9 /synapse | |
parent | Merge pull request #2829 from matrix-org/rav/postgres_in_tests (diff) | |
parent | Add tests for user directory search (diff) | |
download | synapse-4c65b98e4add3e5969057a2f1b97568d554ca7b9.tar.xz |
Merge pull request #2831 from matrix-org/rav/fix-userdir-search-again
Fix SQL for user search
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/storage/user_directory.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/synapse/storage/user_directory.py b/synapse/storage/user_directory.py index f150ef0103..dfdcbb3181 100644 --- a/synapse/storage/user_directory.py +++ b/synapse/storage/user_directory.py @@ -641,13 +641,12 @@ class UserDirectoryStore(SQLBaseStore): """ if self.hs.config.user_directory_search_all_users: - # dummy to keep the number of binds & aliases the same + # make s.user_id null to keep the ordering algorithm happy join_clause = """ - LEFT JOIN ( - SELECT NULL as user_id WHERE NULL = ? - ) AS s USING (user_id)" + CROSS JOIN (SELECT NULL as user_id) AS s """ - where_clause = "" + join_args = () + where_clause = "1=1" else: join_clause = """ LEFT JOIN users_in_public_rooms AS p USING (user_id) @@ -656,6 +655,7 @@ class UserDirectoryStore(SQLBaseStore): WHERE user_id = ? AND share_private ) AS s USING (user_id) """ + join_args = (user_id,) where_clause = "(s.user_id IS NOT NULL OR p.user_id IS NOT NULL)" if isinstance(self.database_engine, PostgresEngine): @@ -697,7 +697,7 @@ class UserDirectoryStore(SQLBaseStore): avatar_url IS NULL LIMIT ? """ % (join_clause, where_clause) - args = (user_id, full_query, exact_query, prefix_query, limit + 1,) + args = join_args + (full_query, exact_query, prefix_query, limit + 1,) elif isinstance(self.database_engine, Sqlite3Engine): search_query = _parse_query_sqlite(search_term) @@ -715,7 +715,7 @@ class UserDirectoryStore(SQLBaseStore): avatar_url IS NULL LIMIT ? """ % (join_clause, where_clause) - args = (user_id, search_query, limit + 1) + args = join_args + (search_query, limit + 1) else: # This should be unreachable. raise Exception("Unrecognized database engine") |