Skip to content

Commit f5ed52c

Browse files
erikjohnstondevonh
andauthored
Move index creation to background update (#18439)
Follow on from #18375. This prevents blocking startup on creating the index, which can take a while --------- Co-authored-by: Devon Hudson <[email protected]>
1 parent 99c15f4 commit f5ed52c

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

changelog.d/18439.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix startup being blocked on creating a new index. Introduced in v1.130.0rc1.

synapse/storage/databases/main/sliding_sync.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ def __init__(
6868
columns=("membership_event_id",),
6969
)
7070

71+
self.db_pool.updates.register_background_index_update(
72+
update_name="sliding_sync_membership_snapshots_user_id_stream_ordering",
73+
index_name="sliding_sync_membership_snapshots_user_id_stream_ordering",
74+
table="sliding_sync_membership_snapshots",
75+
columns=("user_id", "event_stream_ordering"),
76+
replaces_index="sliding_sync_membership_snapshots_user_id",
77+
)
78+
7179
async def get_latest_bump_stamp_for_room(
7280
self,
7381
room_id: str,

synapse/storage/schema/main/delta/92/03_ss_membership_snapshot_idx.sql renamed to synapse/storage/schema/main/delta/92/04_ss_membership_snapshot_idx.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
-- <https://www.gnu.org/licenses/agpl-3.0.html>.
1313

1414
-- So we can fetch all rooms for a given user sorted by stream order
15-
DROP INDEX IF EXISTS sliding_sync_membership_snapshots_user_id;
16-
CREATE INDEX IF NOT EXISTS sliding_sync_membership_snapshots_user_id ON sliding_sync_membership_snapshots(user_id, event_stream_ordering);
15+
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
16+
(9204, 'sliding_sync_membership_snapshots_user_id_stream_ordering', '{}');

0 commit comments

Comments
 (0)