diff --git a/changelog.d/18074.bugfix b/changelog.d/18074.bugfix new file mode 100644 index 00000000000..03e0b959881 --- /dev/null +++ b/changelog.d/18074.bugfix @@ -0,0 +1 @@ +Add index to sliding sync membership snapshot table, to fix a performance issue. \ No newline at end of file diff --git a/synapse/storage/databases/main/sliding_sync.py b/synapse/storage/databases/main/sliding_sync.py index 874dfdcb77a..a287fd2a3fd 100644 --- a/synapse/storage/databases/main/sliding_sync.py +++ b/synapse/storage/databases/main/sliding_sync.py @@ -1,7 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # -# Copyright (C) 2023 New Vector, Ltd +# Copyright (C) 2023, 2025 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 @@ -61,6 +61,13 @@ def __init__( columns=("required_state_id",), ) + self.db_pool.updates.register_background_index_update( + update_name="sliding_sync_membership_snapshots_membership_event_id_idx", + index_name="sliding_sync_membership_snapshots_membership_event_id_idx", + table="sliding_sync_membership_snapshots", + columns=("membership_event_id",), + ) + async def get_latest_bump_stamp_for_room( self, room_id: str, diff --git a/synapse/storage/schema/main/delta/88/07_sliding_sync_membership_snapshot_index.sql b/synapse/storage/schema/main/delta/88/07_sliding_sync_membership_snapshot_index.sql new file mode 100644 index 00000000000..1be484ea191 --- /dev/null +++ b/synapse/storage/schema/main/delta/88/07_sliding_sync_membership_snapshot_index.sql @@ -0,0 +1,15 @@ +-- +-- This file is licensed under the Affero General Public License (AGPL) version 3. +-- +-- Copyright (C) 2025 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 + (8807, 'sliding_sync_membership_snapshots_membership_event_id_idx', '{}');