Skip to content

Commit

Permalink
Add index to sliding_sync_membership_snapshots(membership_event_id)
Browse files Browse the repository at this point in the history
To address a performance problem due to the foreign key on the same
column.
  • Loading branch information
reivilibre committed Jan 10, 2025
1 parent aab3672 commit e92ca3e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion synapse/storage/databases/main/sliding_sync.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
-- <https://www.gnu.org/licenses/agpl-3.0.html>.

INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
(8807, 'sliding_sync_membership_snapshots_membership_event_id_idx', '{}');

0 comments on commit e92ca3e

Please sign in to comment.