From 938c97416d2f3f1e248b2e208fa14874103c5bcc Mon Sep 17 00:00:00 2001 From: reivilibre Date: Thu, 13 Nov 2025 14:26:37 +0000 Subject: [PATCH] Add a shortcut return when there are no events to purge. (#19093) Fixes: #13417 --------- Signed-off-by: Olivier 'reivilibre --- changelog.d/19093.misc | 1 + synapse/storage/databases/main/purge_events.py | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 changelog.d/19093.misc diff --git a/changelog.d/19093.misc b/changelog.d/19093.misc new file mode 100644 index 0000000000..39ada26b68 --- /dev/null +++ b/changelog.d/19093.misc @@ -0,0 +1 @@ +Add a shortcut return when there are no events to purge. \ No newline at end of file diff --git a/synapse/storage/databases/main/purge_events.py b/synapse/storage/databases/main/purge_events.py index 10de1b35a6..d55ea5cf7d 100644 --- a/synapse/storage/databases/main/purge_events.py +++ b/synapse/storage/databases/main/purge_events.py @@ -239,6 +239,16 @@ class PurgeEventsStore(StateGroupWorkerStore, CacheInvalidationWorkerStore): txn.execute("SELECT event_id, should_delete FROM events_to_purge") event_rows = txn.fetchall() + + if len(event_rows) == 0: + logger.info("[purge] no events found to purge") + + # For the sake of cleanliness: drop the temp table. + # This will commit the txn in sqlite, so make sure to keep this actually last. + txn.execute("DROP TABLE events_to_purge") + # no referenced state groups + return set() + logger.info( "[purge] found %i events before cutoff, of which %i can be deleted", len(event_rows),