summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2017-05-10 18:17:41 +0100
committerRichard van der Hoff <richard@matrix.org>2017-05-10 18:44:22 +0100
commit8e345ce46532974aac08c15cf4c90924ec4496d5 (patch)
treee8581b2ac2a87b6bb184026cd7a84a33c1a5fc2e
parentadd some logging to purge_history (diff)
downloadsynapse-8e345ce46532974aac08c15cf4c90924ec4496d5.tar.xz
Don't de-delta state groups we're about to delete
-rw-r--r--synapse/storage/events.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 512828cf34..2a37e6f1a8 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -2080,19 +2080,14 @@ class EventsStore(SQLBaseStore):
         )
 
         state_rows = txn.fetchall()
-        state_groups_to_delete = [sg for sg, in state_rows]
-
-        logger.debug(
-            "[purge] finding state groups which depend on redundant state groups"
-        )
+        state_groups_to_delete = set([sg for sg, in state_rows])
 
         # Now we get all the state groups that rely on these state groups
+        logger.debug("[purge] finding state groups which depend on redundant"
+                     " state groups")
         new_state_edges = []
-        chunks = [
-            state_groups_to_delete[i:i + 100]
-            for i in xrange(0, len(state_groups_to_delete), 100)
-        ]
-        for chunk in chunks:
+        for i in xrange(0, len(state_rows), 100):
+            chunk = [sg for sg, in state_rows[i:i + 100]]
             rows = self._simple_select_many_txn(
                 txn,
                 table="state_group_edges",
@@ -2101,7 +2096,10 @@ class EventsStore(SQLBaseStore):
                 retcols=["state_group"],
                 keyvalues={},
             )
-            new_state_edges.extend(row["state_group"] for row in rows)
+            new_state_edges.extend(
+                row["state_group"] for row in rows
+                if row["state_group"] not in state_groups_to_delete
+            )
 
         # Now we turn the state groups that reference to-be-deleted state groups
         # to non delta versions.