From 182ca78a12c4ae0f37726d43d5e592d669d99ee1 Mon Sep 17 00:00:00 2001
From: Mathieu Velten <mathieuv@matrix.org>
Date: Tue, 17 May 2022 19:01:06 +0200
Subject: [PATCH] Delete events from federation_inbound_events_staging table on
 purge (#12770)

---
 changelog.d/12770.bugfix                       | 1 +
 synapse/storage/databases/main/purge_events.py | 1 +
 tests/rest/admin/test_room.py                  | 1 +
 3 files changed, 3 insertions(+)
 create mode 100644 changelog.d/12770.bugfix

diff --git a/changelog.d/12770.bugfix b/changelog.d/12770.bugfix
new file mode 100644
index 0000000000..a958f9a16b
--- /dev/null
+++ b/changelog.d/12770.bugfix
@@ -0,0 +1 @@
+Delete events from the `federation_inbound_events_staging` table when a room is purged through the admin API.
diff --git a/synapse/storage/databases/main/purge_events.py b/synapse/storage/databases/main/purge_events.py
index 38ba91af4c..c94d5f9f81 100644
--- a/synapse/storage/databases/main/purge_events.py
+++ b/synapse/storage/databases/main/purge_events.py
@@ -417,6 +417,7 @@ class PurgeEventsStore(StateGroupWorkerStore, CacheInvalidationWorkerStore):
             "room_account_data",
             "room_tags",
             "local_current_membership",
+            "federation_inbound_events_staging",
         ):
             logger.info("[purge] removing %s from %s", room_id, table)
             txn.execute("DELETE FROM %s WHERE room_id=?" % (table,), (room_id,))
diff --git a/tests/rest/admin/test_room.py b/tests/rest/admin/test_room.py
index 95282f078e..608d3f2dc3 100644
--- a/tests/rest/admin/test_room.py
+++ b/tests/rest/admin/test_room.py
@@ -2489,4 +2489,5 @@ PURGE_TABLES = [
     "room_tags",
     # "state_groups",  # Current impl leaves orphaned state groups around.
     "state_groups_state",
+    "federation_inbound_events_staging",
 ]
-- 
GitLab