Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repair page tree CLI command #2242

Merged
merged 1 commit into from
May 16, 2023

Conversation

svenseeberg
Copy link
Member

@svenseeberg svenseeberg commented Apr 20, 2023

Short description

Add a shell command that repairs a tree of a given tree node ID.

Proposed changes

  • Loop through all branches of a tree beginning from root node.
  • Sort existing tree nodes by sorting them by existing lft values.
  • Re-calculate lft and rgt values by counting through the leaves.

Side effects

  • This should keep the existing structure of pages as far as possible. Some pages might be in a different order in very few cases.

Resolved issues


Pull Request Review Guidelines

@svenseeberg svenseeberg requested a review from a team as a code owner April 20, 2023 17:22
@codeclimate
Copy link

codeclimate bot commented Apr 20, 2023

Code Climate has analyzed commit 6705a06 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 0.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 75.4% (-0.5% change).

View more on Code Climate.

@svenseeberg svenseeberg force-pushed the feature/repair-tree-shell-command branch from 6221381 to 1c8d99b Compare April 20, 2023 17:29
@svenseeberg svenseeberg changed the title Add repair tree CLI command Add repair page tree CLI command Apr 20, 2023
@svenseeberg svenseeberg force-pushed the feature/repair-tree-shell-command branch 2 times, most recently from d6ffc2e to 97d6bb0 Compare April 20, 2023 17:45
Copy link
Member

@timobrembeck timobrembeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, this is very much needed 😍

In general, it seems to work for a few test cases I set up.
However, it did not catch problems in these cases:

  • Inconsistencies between the tree_id and the parent field
  • Inconsistencies between the depth and the parent field
  • When the lft and rgt values are incorrect in a way that the page is not included in get_children()

I added a few suggestions that take the parent field as single source of truth and adapts all internal tree fields accordingly. I hope this works completely independent of how bad the tree structure is broken.
However, I did not validate my suggestion against the real database, so I would be very interested in the result it produces.

integreat_cms/core/management/commands/repair_tree.py Outdated Show resolved Hide resolved
integreat_cms/core/management/commands/repair_tree.py Outdated Show resolved Hide resolved
integreat_cms/core/management/commands/repair_tree.py Outdated Show resolved Hide resolved
integreat_cms/core/management/commands/repair_tree.py Outdated Show resolved Hide resolved
integreat_cms/core/management/commands/repair_tree.py Outdated Show resolved Hide resolved
integreat_cms/core/management/commands/repair_tree.py Outdated Show resolved Hide resolved
integreat_cms/core/management/commands/repair_tree.py Outdated Show resolved Hide resolved
@svenseeberg svenseeberg force-pushed the feature/repair-tree-shell-command branch from 22b2e46 to 6705a06 Compare April 21, 2023 16:33
Co-authored-by: Timo Ludwig <timo.ludwig@tuerantuer.org>
@svenseeberg svenseeberg force-pushed the feature/repair-tree-shell-command branch from 836ffb1 to 353254e Compare April 22, 2023 13:35
Copy link
Member

@timobrembeck timobrembeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not do super-intensive testing on this, but seems to work well for a few inconsistencies I manually created.
Would be interesting to see how this performs on the production system.
If possible, it would also be cool to create test cases from the currently broken production data, but it's more important that we finally merge this 😄

@svenseeberg svenseeberg merged commit 2f41e0f into develop May 16, 2023
5 checks passed
@svenseeberg svenseeberg deleted the feature/repair-tree-shell-command branch May 16, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants