summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-11-06 17:02:05 +0000
committerErik Johnston <erik@matrix.org>2019-11-06 17:02:08 +0000
commit5c3363233cca7044a333b7e19ba239eaf5587ff8 (patch)
treefd4d33bdc81b530cd7233654ad79ceaa2a616756 /synapse
parentUse correct type annotation (diff)
downloadsynapse-5c3363233cca7044a333b7e19ba239eaf5587ff8.tar.xz
Fix deleting state groups during room purge.
And fix the tests to actually test that things got deleted.
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/data_stores/main/events.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/synapse/storage/data_stores/main/events.py b/synapse/storage/data_stores/main/events.py
index d69c59f5a1..946823876a 100644
--- a/synapse/storage/data_stores/main/events.py
+++ b/synapse/storage/data_stores/main/events.py
@@ -1633,7 +1633,20 @@ class EventsStore(
         return self.runInteraction("purge_room", self._purge_room_txn, room_id)
 
     def _purge_room_txn(self, txn, room_id):
-        # First delete tables which lack an index on room_id but have one on event_id
+        # First we fetch all the state groups that should be deleted, before
+        # we delete that information.
+        txn.execute(
+            """
+                SELECT DISTINCT state_group FROM events
+                INNER JOIN event_to_state_groups USING(event_id)
+                WHERE events.room_id = ?
+            """,
+            (room_id,),
+        )
+
+        state_groups = [row[0] for row in txn]
+
+        # Now we delete tables which lack an index on room_id but have one on event_id
         for table in (
             "event_auth",
             "event_edges",
@@ -1717,18 +1730,6 @@ class EventsStore(
         #       index on them. In any case we should be clearing out 'stream' tables
         #       periodically anyway (#5888)
 
-        # Now we fetch all the state groups that should be deleted.
-        txn.execute(
-            """
-                SELECT DISTINCT state_group FROM events
-                INNER JOIN event_to_state_groups USING(event_id)
-                WHERE events.room_id = ?
-            """,
-            (room_id,),
-        )
-
-        state_groups = [row[0] for row in txn]
-
         # TODO: we could probably usefully do a bunch of cache invalidation here
 
         logger.info("[purge] done")