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

Fix perf of get_cross_signing_keys #9116

Merged
merged 4 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.d/9114.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fix bug in federation catchup logic that caused outbound federation to be delayed for large servers after start up. Introduced in v1.21.0.
Fix bugs in federation catchup logic that caused outbound federation to be delayed for large servers after start up. Introduced in v1.8.0 and v1.21.0.
1 change: 1 addition & 0 deletions changelog.d/9116.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bugs in federation catchup logic that caused outbound federation to be delayed for large servers after start up. Introduced in v1.8.0 and v1.21.0.
21 changes: 9 additions & 12 deletions synapse/storage/databases/main/end_to_end_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,15 @@ def _get_bare_e2e_cross_signing_keys_bulk_txn(
clause, params = make_in_list_sql_clause(
txn.database_engine, "k.user_id", user_chunk
)
sql = (
"""
SELECT k.user_id, k.keytype, k.keydata, k.stream_id
FROM e2e_cross_signing_keys k
INNER JOIN (SELECT user_id, keytype, MAX(stream_id) AS stream_id
FROM e2e_cross_signing_keys
GROUP BY user_id, keytype) s
USING (user_id, stream_id, keytype)
WHERE
"""
+ clause
)

sql = """
SELECT DISTINCT ON (user_id, keytype) user_id, keytype, k.keydata, stream_id
clokep marked this conversation as resolved.
Show resolved Hide resolved
FROM e2e_cross_signing_keys
WHERE %(clause)s
ORDER BY user_id
""" % {
"clause": clause
}

txn.execute(sql, params)
rows = self.db_pool.cursor_to_dict(txn)
Expand Down