From 90d0e035dd872150c5a99a42659f900f0a00949d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 28 Aug 2024 14:14:09 +0100 Subject: [PATCH] Fix port script tests by handling empty DBs correctly --- synapse/storage/databases/main/events_bg_updates.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/synapse/storage/databases/main/events_bg_updates.py b/synapse/storage/databases/main/events_bg_updates.py index 946d5ec65b..6b080f7678 100644 --- a/synapse/storage/databases/main/events_bg_updates.py +++ b/synapse/storage/databases/main/events_bg_updates.py @@ -2323,6 +2323,12 @@ def _resolve_stale_data_in_sliding_sync_joined_rooms_table( value_values=[() for x in range(len(chunk))], ) else: + txn.execute("SELECT 1 FROM local_current_membership LIMIT 1") + row = txn.fetchone() + if row is None: + # There are no rooms, so don't schedule the bg update. + return + # Re-run the `sliding_sync_joined_rooms_to_recalculate` prefill if there is # nothing in the `sliding_sync_joined_rooms` table DatabasePool.simple_upsert_txn_native_upsert( @@ -2430,6 +2436,12 @@ def _resolve_stale_data_in_sliding_sync_membership_snapshots_table( keys=("user_id", "room_id"), values=chunk, ) + else: + txn.execute("SELECT 1 FROM local_current_membership LIMIT 1") + row = txn.fetchone() + if row is None: + # There are no rooms, so don't schedule the bg update. + return # Now kick-off the background update to catch-up with what we missed while Synapse # was downgraded.