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

Commit d6bda5a

Browse files
authored
Add index to improve performance of the /timestamp_to_event endpoint used for jumping to a specific date in the timeline of a room. (#14799)
1 parent 73f0978 commit d6bda5a

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

changelog.d/14799.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add index to improve performance of the `/timestamp_to_event` endpoint used for jumping to a specific date in the timeline of a room.

synapse/storage/databases/main/events_bg_updates.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class _BackgroundUpdates:
6969

7070
EVENTS_POPULATE_STATE_KEY_REJECTIONS = "events_populate_state_key_rejections"
7171

72+
EVENTS_JUMP_TO_DATE_INDEX = "events_jump_to_date_index"
73+
7274

7375
@attr.s(slots=True, frozen=True, auto_attribs=True)
7476
class _CalculateChainCover:
@@ -260,6 +262,16 @@ def __init__(
260262
self._background_events_populate_state_key_rejections,
261263
)
262264

265+
# Add an index that would be useful for jumping to date using
266+
# get_event_id_for_timestamp.
267+
self.db_pool.updates.register_background_index_update(
268+
_BackgroundUpdates.EVENTS_JUMP_TO_DATE_INDEX,
269+
index_name="events_jump_to_date_idx",
270+
table="events",
271+
columns=["room_id", "origin_server_ts"],
272+
where_clause="NOT outlier",
273+
)
274+
263275
async def _background_reindex_fields_sender(
264276
self, progress: JsonDict, batch_size: int
265277
) -> int:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Copyright 2023 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 (ordering, update_name, progress_json) VALUES
17+
(7324, 'events_jump_to_date_index', '{}');

0 commit comments

Comments
 (0)