From 2acaabc071071288f9cb8aedcca3f5cf5fb52f7e Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 5 Apr 2024 14:51:23 +0100 Subject: [PATCH 1/3] Add forgotten schema delta This should have been in #17045. Whoops. --- .../main/delta/84/04_access_token_index.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 synapse/storage/schema/main/delta/84/04_access_token_index.sql diff --git a/synapse/storage/schema/main/delta/84/04_access_token_index.sql b/synapse/storage/schema/main/delta/84/04_access_token_index.sql new file mode 100644 index 00000000000..d2fa945c8fa --- /dev/null +++ b/synapse/storage/schema/main/delta/84/04_access_token_index.sql @@ -0,0 +1,15 @@ +-- +-- This file is licensed under the Affero General Public License (AGPL) version 3. +-- +-- Copyright (C) 2023 New Vector, Ltd +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as +-- published by the Free Software Foundation, either version 3 of the +-- License, or (at your option) any later version. +-- +-- See the GNU Affero General Public License for more details: +-- . + +INSERT INTO background_updates (ordering, update_name, progress_json) VALUES + (8404, 'access_tokens_refresh_token_id_idx', '{}'); From 1822896c65c864a6687b46fc8034c545ca0ac47f Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 5 Apr 2024 14:52:20 +0100 Subject: [PATCH 2/3] Newsfile --- changelog.d/17054.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/17054.misc diff --git a/changelog.d/17054.misc b/changelog.d/17054.misc new file mode 100644 index 00000000000..0d042a43ff8 --- /dev/null +++ b/changelog.d/17054.misc @@ -0,0 +1 @@ +Improve database performance by adding a missing index to `access_tokens.refresh_token_id`. From 2d4d5a94d19e7531bf2310c8fe265f8669dc0600 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 5 Apr 2024 15:05:51 +0100 Subject: [PATCH 3/3] Fix port script --- synapse/storage/databases/main/registration.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/synapse/storage/databases/main/registration.py b/synapse/storage/databases/main/registration.py index 30a3ae30553..29bf47befc9 100644 --- a/synapse/storage/databases/main/registration.py +++ b/synapse/storage/databases/main/registration.py @@ -2108,6 +2108,13 @@ def __init__( unique=False, ) + self.db_pool.updates.register_background_index_update( + update_name="access_tokens_refresh_token_id_idx", + index_name="access_tokens_refresh_token_id_idx", + table="access_tokens", + columns=("refresh_token_id",), + ) + async def _background_update_set_deactivated_flag( self, progress: JsonDict, batch_size: int ) -> int: @@ -2266,13 +2273,6 @@ def __init__( ): super().__init__(database, db_conn, hs) - self.db_pool.updates.register_background_index_update( - update_name="access_tokens_refresh_token_id_idx", - index_name="access_tokens_refresh_token_id_idx", - table="access_tokens", - columns=("refresh_token_id",), - ) - self._ignore_unknown_session_error = ( hs.config.server.request_token_inhibit_3pid_errors )