Tidy purge code and add some comments
Try to make this clearer with more comments and some variable renames
This commit is contained in:
parent
8e345ce465
commit
dc026bb16f
|
@ -2080,14 +2080,19 @@ class EventsStore(SQLBaseStore):
|
||||||
)
|
)
|
||||||
|
|
||||||
state_rows = txn.fetchall()
|
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])
|
state_groups_to_delete = set([sg for sg, in state_rows])
|
||||||
|
|
||||||
# Now we get all the state groups that rely on these state groups
|
# Now we get all the state groups that rely on these state groups
|
||||||
logger.debug("[purge] finding state groups which depend on redundant"
|
logger.debug("[purge] finding state groups which depend on redundant"
|
||||||
" state groups")
|
" state groups")
|
||||||
new_state_edges = []
|
remaining_state_groups = []
|
||||||
for i in xrange(0, len(state_rows), 100):
|
for i in xrange(0, len(state_rows), 100):
|
||||||
chunk = [sg for sg, in state_rows[i:i + 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(
|
rows = self._simple_select_many_txn(
|
||||||
txn,
|
txn,
|
||||||
table="state_group_edges",
|
table="state_group_edges",
|
||||||
|
@ -2096,26 +2101,28 @@ class EventsStore(SQLBaseStore):
|
||||||
retcols=["state_group"],
|
retcols=["state_group"],
|
||||||
keyvalues={},
|
keyvalues={},
|
||||||
)
|
)
|
||||||
new_state_edges.extend(
|
remaining_state_groups.extend(
|
||||||
row["state_group"] for row in rows
|
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
|
if row["state_group"] not in state_groups_to_delete
|
||||||
)
|
)
|
||||||
|
|
||||||
# Now we turn the state groups that reference to-be-deleted state groups
|
# Now we turn the state groups that reference to-be-deleted state
|
||||||
# to non delta versions.
|
# groups to non delta versions.
|
||||||
for new_state_edge in new_state_edges:
|
for sg in remaining_state_groups:
|
||||||
logger.debug("[purge] de-delta-ing remaining state group %s",
|
logger.debug("[purge] de-delta-ing remaining state group %s", sg)
|
||||||
new_state_edge)
|
|
||||||
curr_state = self._get_state_groups_from_groups_txn(
|
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(
|
self._simple_delete_txn(
|
||||||
txn,
|
txn,
|
||||||
table="state_groups_state",
|
table="state_groups_state",
|
||||||
keyvalues={
|
keyvalues={
|
||||||
"state_group": new_state_edge,
|
"state_group": sg,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2123,7 +2130,7 @@ class EventsStore(SQLBaseStore):
|
||||||
txn,
|
txn,
|
||||||
table="state_group_edges",
|
table="state_group_edges",
|
||||||
keyvalues={
|
keyvalues={
|
||||||
"state_group": new_state_edge,
|
"state_group": sg,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2132,7 +2139,7 @@ class EventsStore(SQLBaseStore):
|
||||||
table="state_groups_state",
|
table="state_groups_state",
|
||||||
values=[
|
values=[
|
||||||
{
|
{
|
||||||
"state_group": new_state_edge,
|
"state_group": sg,
|
||||||
"room_id": room_id,
|
"room_id": room_id,
|
||||||
"type": key[0],
|
"type": key[0],
|
||||||
"state_key": key[1],
|
"state_key": key[1],
|
||||||
|
|
Loading…
Reference in New Issue