mirror of
https://github.com/element-hq/synapse.git
synced 2025-03-14 09:45:51 +00:00
Cleanup deleted state group references (#18165)
### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters))
This commit is contained in:
parent
2d4f28915e
commit
ecad88f5c5
3 changed files with 43 additions and 1 deletions
1
changelog.d/18165.bugfix
Normal file
1
changelog.d/18165.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Cleanup deleted state group references.
|
|
@ -828,10 +828,18 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
|
|||
"DELETE FROM state_groups_state WHERE state_group = ?",
|
||||
[(sg,) for sg in state_groups_to_delete],
|
||||
)
|
||||
txn.execute_batch(
|
||||
"DELETE FROM state_group_edges WHERE state_group = ?",
|
||||
[(sg,) for sg in state_groups_to_delete],
|
||||
)
|
||||
txn.execute_batch(
|
||||
"DELETE FROM state_groups WHERE id = ?",
|
||||
[(sg,) for sg in state_groups_to_delete],
|
||||
)
|
||||
txn.execute_batch(
|
||||
"DELETE FROM state_groups_pending_deletion WHERE state_group = ?",
|
||||
[(sg,) for sg in state_groups_to_delete],
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
|
|
@ -247,7 +247,7 @@ class PurgeTests(HomeserverTestCase):
|
|||
1 + self.state_deletion_store.DELAY_BEFORE_DELETION_MS / 1000
|
||||
)
|
||||
|
||||
# We expect that the unreferenced state group has been deleted.
|
||||
# We expect that the unreferenced state group has been deleted from all tables.
|
||||
row = self.get_success(
|
||||
self.state_store.db_pool.simple_select_one_onecol(
|
||||
table="state_groups",
|
||||
|
@ -259,6 +259,39 @@ class PurgeTests(HomeserverTestCase):
|
|||
)
|
||||
self.assertIsNone(row)
|
||||
|
||||
row = self.get_success(
|
||||
self.state_store.db_pool.simple_select_one_onecol(
|
||||
table="state_groups_state",
|
||||
keyvalues={"state_group": unreferenced_state_group},
|
||||
retcol="state_group",
|
||||
allow_none=True,
|
||||
desc="test_purge_unreferenced_state_group",
|
||||
)
|
||||
)
|
||||
self.assertIsNone(row)
|
||||
|
||||
row = self.get_success(
|
||||
self.state_store.db_pool.simple_select_one_onecol(
|
||||
table="state_group_edges",
|
||||
keyvalues={"state_group": unreferenced_state_group},
|
||||
retcol="state_group",
|
||||
allow_none=True,
|
||||
desc="test_purge_unreferenced_state_group",
|
||||
)
|
||||
)
|
||||
self.assertIsNone(row)
|
||||
|
||||
row = self.get_success(
|
||||
self.state_store.db_pool.simple_select_one_onecol(
|
||||
table="state_groups_pending_deletion",
|
||||
keyvalues={"state_group": unreferenced_state_group},
|
||||
retcol="state_group",
|
||||
allow_none=True,
|
||||
desc="test_purge_unreferenced_state_group",
|
||||
)
|
||||
)
|
||||
self.assertIsNone(row)
|
||||
|
||||
# We expect there to now only be one state group for the room, which is
|
||||
# the state group of the last event (as the only outlier).
|
||||
state_groups = self.get_success(
|
||||
|
|
Loading…
Add table
Reference in a new issue