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

Commit a494e0b

Browse files
erikjohnstonH-Shay
authored andcommitted
Add another index to device_lists_changes_in_room (#14534)
This helps avoid reading unnecessarily large amounts of data from the table when querying with a set of room IDs.
1 parent 58fedf5 commit a494e0b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

changelog.d/14534.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve DB performance by reducing amount of data that gets read in `device_lists_changes_in_room`.

synapse/storage/databases/main/devices.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,13 @@ def __init__(
14411441
self._remove_duplicate_outbound_pokes,
14421442
)
14431443

1444+
self.db_pool.updates.register_background_index_update(
1445+
"device_lists_changes_in_room_by_room_index",
1446+
index_name="device_lists_changes_in_room_by_room_idx",
1447+
table="device_lists_changes_in_room",
1448+
columns=["room_id", "stream_id"],
1449+
)
1450+
14441451
async def _drop_device_list_streams_non_unique_indexes(
14451452
self, progress: JsonDict, batch_size: int
14461453
) -> int:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Copyright 2022 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+
17+
-- Adds an index on `device_lists_changes_in_room (room_id, stream_id)`, which
18+
-- speeds up `/sync` queries.
19+
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
20+
(7313, 'device_lists_changes_in_room_by_room_index', '{}');

0 commit comments

Comments
 (0)