Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit f2f8a21

Browse files
committed
Drop the indexes in the background.
1 parent ad4201c commit f2f8a21

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

synapse/storage/databases/main/event_push_actions.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
)
101101
from synapse.storage.databases.main.receipts import ReceiptsWorkerStore
102102
from synapse.storage.databases.main.stream import StreamWorkerStore
103+
from synapse.types import JsonDict
103104
from synapse.util import json_encoder
104105
from synapse.util.caches.descriptors import cached
105106

@@ -304,6 +305,39 @@ def __init__(
304305
table="event_push_summary",
305306
)
306307

308+
self.db_pool.updates.register_background_update_handler(
309+
"event_push_drop_null_thread_id_indexes",
310+
self._background_drop_null_thread_id_indexes,
311+
)
312+
313+
async def _background_drop_null_thread_id_indexes(
314+
self, progress: JsonDict, batch_size: int
315+
) -> int:
316+
"""
317+
Drop the indexes used to find null thread_ids for event_push_actions and
318+
event_push_summary.
319+
"""
320+
321+
def drop_null_thread_id_indexes_txn(
322+
txn: LoggingTransaction, start_stream_ordering: int
323+
) -> None:
324+
sql = "DROP INDEX IF EXISTS event_push_actions_thread_id_null"
325+
logger.debug("[SQL] %s", sql)
326+
txn.execute(sql)
327+
328+
sql = "DROP INDEX IF EXISTS event_push_summary_thread_id_null"
329+
logger.debug("[SQL] %s", sql)
330+
txn.execute(sql)
331+
332+
await self.db_pool.runInteraction(
333+
"drop_null_thread_id_indexes_txn",
334+
drop_null_thread_id_indexes_txn,
335+
)
336+
await self.db_pool.updates._end_background_update(
337+
"event_push_drop_null_thread_id_indexes"
338+
)
339+
return 0
340+
307341
async def get_unread_counts_by_room_for_user(self, user_id: str) -> Dict[str, int]:
308342
"""Get the notification count by room for a user. Only considers notifications,
309343
not highlight or unread counts, and threads are currently aggregated under their room.

synapse/storage/schema/main/delta/76/05thread_notifications_not_null_event_push_actions.sql.postgres

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,3 @@ ALTER TABLE event_push_actions
2525
-- only needs a SHARE UPDATE EXCLUSIVE lock but can still take a while to complete.
2626
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
2727
(7605, 'event_push_actions_thread_id', '{}');
28-
29-
-- Drop the indexes used to find null thread_ids.
30-
DROP INDEX IF EXISTS event_push_actions_thread_id_null;

synapse/storage/schema/main/delta/76/05thread_notifications_not_null_event_push_summary.sql.postgres

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ ALTER TABLE event_push_summary
2424
-- We then validate the constraint which doesn't need to worry about new data. It
2525
-- only needs a SHARE UPDATE EXCLUSIVE lock but can still take a while to complete.
2626
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
27-
(7605, 'event_push_summary_thread_id', '{}');
28-
29-
-- Drop the indexes used to find null thread_ids.
30-
DROP INDEX IF EXISTS event_push_summary_thread_id_null;
27+
(7605, 'event_push_summary_thread_id', '{}'),
28+
-- Also clean-up the old indexes.
29+
(7605, 'event_push_drop_null_thread_id_indexes', '{}');;

0 commit comments

Comments
 (0)