summary refs log tree commit diff
path: root/synapse/storage/events.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2017-05-11 10:56:12 +0100
committerRichard van der Hoff <richard@matrix.org>2017-05-11 10:56:12 +0100
commitdc026bb16ff552e9424be217ec5c64104c8b193f (patch)
treee2519b10da39c4b362fa8cc9ac86824eb1890e12 /synapse/storage/events.py
parentDon't de-delta state groups we're about to delete (diff)
downloadsynapse-dc026bb16ff552e9424be217ec5c64104c8b193f.tar.xz
Tidy purge code and add some comments
Try to make this clearer with more comments and some variable renames
Diffstat (limited to '')
-rw-r--r--synapse/storage/events.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 2a37e6f1a8..dbd63078c6 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -2080,14 +2080,19 @@ class EventsStore(SQLBaseStore):
         )
 
         state_rows = txn.fetchall()
+
+        # make a set of the redundant state groups, so that we can look them up
+        # efficiently
         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 = []
+        remaining_state_groups = []
         for i in xrange(0, len(state_rows), 100):
             chunk = [sg for sg, in state_rows[i:i + 100]]
+            # look for state groups whose prev_state_group is one we are about
+            # to delete
             rows = self._simple_select_many_txn(
                 txn,
                 table="state_group_edges",
@@ -2096,26 +2101,28 @@ class EventsStore(SQLBaseStore):
                 retcols=["state_group"],
                 keyvalues={},
             )
-            new_state_edges.extend(
+            remaining_state_groups.extend(
                 row["state_group"] for row in rows
+
+                # exclude state groups we are about to delete: no point in
+                # updating them
                 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.
-        for new_state_edge in new_state_edges:
-            logger.debug("[purge] de-delta-ing remaining state group %s",
-                         new_state_edge)
+        # Now we turn the state groups that reference to-be-deleted state
+        # groups to non delta versions.
+        for sg in remaining_state_groups:
+            logger.debug("[purge] de-delta-ing remaining state group %s", sg)
             curr_state = self._get_state_groups_from_groups_txn(
-                txn, [new_state_edge], types=None
+                txn, [sg], types=None
             )
-            curr_state = curr_state[new_state_edge]
+            curr_state = curr_state[sg]
 
             self._simple_delete_txn(
                 txn,
                 table="state_groups_state",
                 keyvalues={
-                    "state_group": new_state_edge,
+                    "state_group": sg,
                 }
             )
 
@@ -2123,7 +2130,7 @@ class EventsStore(SQLBaseStore):
                 txn,
                 table="state_group_edges",
                 keyvalues={
-                    "state_group": new_state_edge,
+                    "state_group": sg,
                 }
             )
 
@@ -2132,7 +2139,7 @@ class EventsStore(SQLBaseStore):
                 table="state_groups_state",
                 values=[
                     {
-                        "state_group": new_state_edge,
+                        "state_group": sg,
                         "room_id": room_id,
                         "type": key[0],
                         "state_key": key[1],