Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix appservice room list pagination #6154

Merged
merged 2 commits into from Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6154.misc
@@ -0,0 +1 @@
Improve performance of the public room list directory.
36 changes: 18 additions & 18 deletions synapse/storage/room.py
Expand Up @@ -150,6 +150,24 @@ def get_largest_public_rooms(
where_clauses = []
query_args = []

if network_tuple:
if network_tuple.appservice_id:
published_sql = """
SELECT room_id from appservice_room_list
WHERE appservice_id = ? AND network_id = ?
"""
query_args.append(network_tuple.appservice_id)
query_args.append(network_tuple.network_id)
else:
published_sql = """
SELECT room_id FROM rooms WHERE is_public
"""
else:
published_sql = """
SELECT room_id FROM rooms WHERE is_public
UNION SELECT room_id from appservice_room_list
"""

# Work out the bounds if we're given them, these bounds look slightly
# odd, but are designed to help query planner use indices by pulling
# out a common bound.
Expand Down Expand Up @@ -188,24 +206,6 @@ def get_largest_public_rooms(
)
query_args += [search_term, search_term, search_term]

if network_tuple:
if network_tuple.appservice_id:
published_sql = """
SELECT room_id from appservice_room_list
WHERE appservice_id = ? AND network_id = ?
"""
query_args.append(network_tuple.appservice_id)
query_args.append(network_tuple.network_id)
else:
published_sql = """
SELECT room_id FROM rooms WHERE is_public
"""
else:
published_sql = """
SELECT room_id FROM rooms WHERE is_public
UNION SELECT room_id from appservice_room_list
"""

where_clause = ""
if where_clauses:
where_clause = " AND " + " AND ".join(where_clauses)
Expand Down