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

Commit 1eb9de9

Browse files
authored
Improve start time by adding index to e2e_cross_signing_keys (#8694)
We do a `SELECT MAX(stream_id) FROM e2e_cross_signing_keys` on startup.
1 parent 11fd90a commit 1eb9de9

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

changelog.d/8694.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve start time by adding an index to `e2e_cross_signing_keys.stream_id`.

scripts/synapse_port_db

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ from synapse.storage.database import DatabasePool, make_conn
4040
from synapse.storage.databases.main.client_ips import ClientIpBackgroundUpdateStore
4141
from synapse.storage.databases.main.deviceinbox import DeviceInboxBackgroundUpdateStore
4242
from synapse.storage.databases.main.devices import DeviceBackgroundUpdateStore
43+
from synapse.storage.databases.main.end_to_end_keys import EndToEndKeyBackgroundStore
4344
from synapse.storage.databases.main.events_bg_updates import (
4445
EventsBackgroundUpdatesStore,
4546
)
@@ -174,6 +175,7 @@ class Store(
174175
StateBackgroundUpdateStore,
175176
MainStateBackgroundUpdateStore,
176177
UserDirectoryBackgroundUpdateStore,
178+
EndToEndKeyBackgroundStore,
177179
StatsStore,
178180
):
179181
def execute(self, f, *args, **kwargs):

synapse/storage/databases/main/end_to_end_keys.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from synapse.logging.opentracing import log_kv, set_tag, trace
2626
from synapse.storage._base import SQLBaseStore, db_to_json
27-
from synapse.storage.database import make_in_list_sql_clause
27+
from synapse.storage.database import DatabasePool, make_in_list_sql_clause
2828
from synapse.storage.types import Cursor
2929
from synapse.types import JsonDict
3030
from synapse.util import json_encoder
@@ -33,6 +33,7 @@
3333

3434
if TYPE_CHECKING:
3535
from synapse.handlers.e2e_keys import SignatureListItem
36+
from synapse.server import HomeServer
3637

3738

3839
@attr.s(slots=True)
@@ -47,7 +48,20 @@ class DeviceKeyLookupResult:
4748
keys = attr.ib(type=Optional[JsonDict])
4849

4950

50-
class EndToEndKeyWorkerStore(SQLBaseStore):
51+
class EndToEndKeyBackgroundStore(SQLBaseStore):
52+
def __init__(self, database: DatabasePool, db_conn: Connection, hs: "HomeServer"):
53+
super().__init__(database, db_conn, hs)
54+
55+
self.db_pool.updates.register_background_index_update(
56+
"e2e_cross_signing_keys_idx",
57+
index_name="e2e_cross_signing_keys_stream_idx",
58+
table="e2e_cross_signing_keys",
59+
columns=["stream_id"],
60+
unique=True,
61+
)
62+
63+
64+
class EndToEndKeyWorkerStore(EndToEndKeyBackgroundStore):
5165
async def get_e2e_device_keys_for_federation_query(
5266
self, user_id: str
5367
) -> Tuple[int, List[JsonDict]]:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Copyright 2020 The Matrix.org Foundation C.I.C
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
INSERT INTO background_updates (update_name, progress_json) VALUES
17+
('e2e_cross_signing_keys_idx', '{}');

0 commit comments

Comments
 (0)