Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
d2479c68
Unverified
Commit
d2479c68
authored
4 years ago
by
Erik Johnston
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix perf of get_cross_signing_keys (#9116)
parent
659c415e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/9114.bugfix
+1
-1
1 addition, 1 deletion
changelog.d/9114.bugfix
changelog.d/9116.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/9116.bugfix
synapse/storage/databases/main/end_to_end_keys.py
+28
-13
28 additions, 13 deletions
synapse/storage/databases/main/end_to_end_keys.py
with
30 additions
and
14 deletions
changelog.d/9114.bugfix
+
1
−
1
View file @
d2479c68
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 bug
s
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.
This diff is collapsed.
Click to expand it.
changelog.d/9116.bugfix
0 → 100644
+
1
−
0
View file @
d2479c68
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.
This diff is collapsed.
Click to expand it.
synapse/storage/databases/main/end_to_end_keys.py
+
28
−
13
View file @
d2479c68
...
@@ -25,6 +25,7 @@ from twisted.enterprise.adbapi import Connection
...
@@ -25,6 +25,7 @@ from twisted.enterprise.adbapi import Connection
from
synapse.logging.opentracing
import
log_kv
,
set_tag
,
trace
from
synapse.logging.opentracing
import
log_kv
,
set_tag
,
trace
from
synapse.storage._base
import
SQLBaseStore
,
db_to_json
from
synapse.storage._base
import
SQLBaseStore
,
db_to_json
from
synapse.storage.database
import
DatabasePool
,
make_in_list_sql_clause
from
synapse.storage.database
import
DatabasePool
,
make_in_list_sql_clause
from
synapse.storage.engines
import
PostgresEngine
from
synapse.storage.types
import
Cursor
from
synapse.storage.types
import
Cursor
from
synapse.types
import
JsonDict
from
synapse.types
import
JsonDict
from
synapse.util
import
json_encoder
from
synapse.util
import
json_encoder
...
@@ -513,21 +514,35 @@ class EndToEndKeyWorkerStore(EndToEndKeyBackgroundStore):
...
@@ -513,21 +514,35 @@ class EndToEndKeyWorkerStore(EndToEndKeyBackgroundStore):
for
user_chunk
in
batch_iter
(
user_ids
,
100
):
for
user_chunk
in
batch_iter
(
user_ids
,
100
):
clause
,
params
=
make_in_list_sql_clause
(
clause
,
params
=
make_in_list_sql_clause
(
txn
.
database_engine
,
"
k.user_id
"
,
user_chunk
txn
.
database_engine
,
"
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
)
)
# Fetch the latest key for each type per user.
if
isinstance
(
self
.
database_engine
,
PostgresEngine
):
# The `DISTINCT ON` clause will pick the *first* row it
# encounters, so ordering by stream ID desc will ensure we get
# the latest key.
sql
=
"""
SELECT DISTINCT ON (user_id, keytype) user_id, keytype, keydata, stream_id
FROM e2e_cross_signing_keys
WHERE %(clause)s
ORDER BY user_id, keytype, stream_id DESC
"""
%
{
"
clause
"
:
clause
}
else
:
# SQLite has special handling for bare columns when using
# MIN/MAX with a `GROUP BY` clause where it picks the value from
# a row that matches the MIN/MAX.
sql
=
"""
SELECT user_id, keytype, keydata, MAX(stream_id)
FROM e2e_cross_signing_keys
WHERE %(clause)s
GROUP BY user_id, keytype
"""
%
{
"
clause
"
:
clause
}
txn
.
execute
(
sql
,
params
)
txn
.
execute
(
sql
,
params
)
rows
=
self
.
db_pool
.
cursor_to_dict
(
txn
)
rows
=
self
.
db_pool
.
cursor_to_dict
(
txn
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment