From 26a27e06b960e30e2f4f0a5054ffdacc848150c9 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Thu, 13 Jun 2019 15:57:55 +0100 Subject: Create the index in a background update --- synapse/storage/profile.py | 15 +++++++++++++-- .../delta/54/profile_replication_status_index.sql | 16 ---------------- .../delta/55/profile_replication_status_index.sql | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 18 deletions(-) delete mode 100644 synapse/storage/schema/delta/54/profile_replication_status_index.sql create mode 100644 synapse/storage/schema/delta/55/profile_replication_status_index.sql diff --git a/synapse/storage/profile.py b/synapse/storage/profile.py index 04908cbc35..919b1f1641 100644 --- a/synapse/storage/profile.py +++ b/synapse/storage/profile.py @@ -19,12 +19,12 @@ from twisted.internet import defer from synapse.api.errors import StoreError from synapse.storage.roommember import ProfileInfo -from ._base import SQLBaseStore +from . import background_updates BATCH_SIZE = 100 -class ProfileWorkerStore(SQLBaseStore): +class ProfileWorkerStore(background_updates.BackgroundUpdateStore): @defer.inlineCallbacks def get_profileinfo(self, user_localpart): try: @@ -166,6 +166,17 @@ class ProfileWorkerStore(SQLBaseStore): class ProfileStore(ProfileWorkerStore): + def __init__(self, db_conn, hs): + + super(ProfileStore, self).__init__(db_conn, hs) + + self.register_background_index_update( + "profile_replication_status_host_index", + index_name="profile_replication_status_idx", + table="profile_replication_status", + columns=["host"], + ) + def add_remote_profile_cache(self, user_id, displayname, avatar_url): """Ensure we are caching the remote user's profiles. diff --git a/synapse/storage/schema/delta/54/profile_replication_status_index.sql b/synapse/storage/schema/delta/54/profile_replication_status_index.sql deleted file mode 100644 index 7c20cb5a44..0000000000 --- a/synapse/storage/schema/delta/54/profile_replication_status_index.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* Copyright 2019 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -CREATE UNIQUE INDEX profile_replication_status_idx ON profile_replication_status(host); diff --git a/synapse/storage/schema/delta/55/profile_replication_status_index.sql b/synapse/storage/schema/delta/55/profile_replication_status_index.sql new file mode 100644 index 0000000000..18a0f7e10c --- /dev/null +++ b/synapse/storage/schema/delta/55/profile_replication_status_index.sql @@ -0,0 +1,17 @@ +/* Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +INSERT INTO background_updates (update_name, progress_json) VALUES + ('profile_replication_status_host_index', '{}'); -- cgit 1.5.1