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

FIX Renaming a parent page breaks the path to children ones #428

Conversation

mbayane
Copy link

@mbayane mbayane commented Jun 26, 2024

FIX Renaming a parent page breaks the path to children ones ( When a parent slug page update the children path breaks , adding or delete charactere depending the difference between len(new_path_url) and len(old_path_url)

@DiogoMarques29
Copy link
Collaborator

Hey @mbayane,

Thanks for the PR.

I noticed that this change might introduce a performance issue because we are executing a save query for each descendant. Depending on the size of the tree, this could lead to timeout issues.

Could you please refactor the code so that the update happens in a single query? Here’s a suggested approach:

descendants = Page.objects.rewrite(False).filter(path__startswith=page.path).exclude(
    **{localized_url_path: None}).exclude(pk=page.pk)

update_descendants = []
for descendant in descendants:
    old_descendant_url_path = getattr(descendant, localized_url_path)
    if old_descendant_url_path.startswith(old_url_path):
        new_descendant_url_path = new_url_path + old_descendant_url_path[len(old_url_path):]
        setattr(descendant, localized_url_path, new_descendant_url_path)
        update_descendants.append(descendant)

# Use bulk update for performance
Page.objects.bulk_update(update_descendants, [localized_url_path])

This should help maintain performance by reducing the number of database queries.

Thanks again for your contribution!

@mbayane
Copy link
Author

mbayane commented Jul 17, 2024

update_descendants

Hello @DiogoMarques29,

Thanks for your reply and suggestions.

i will update it shortly

Regards

… to Update all descendants in a single query (bulk update) to avoid performance issue)
@mbayane mbayane changed the title FIX Renaming a parent page breaks the path to children ones FIX Renaming a parent page breaks the path to children ones... Jul 17, 2024
@mbayane mbayane changed the base branch from master to django2 July 17, 2024 19:01
@mbayane mbayane changed the base branch from django2 to master July 17, 2024 19:01
@mbayane mbayane changed the title FIX Renaming a parent page breaks the path to children ones... FIX Renaming a parent page breaks the path to children ones Jul 17, 2024
@mbayane
Copy link
Author

mbayane commented Jul 17, 2024

Hello @DiogoMarques29,

Changes pushed

Thanks

@DiogoMarques29
Copy link
Collaborator

Had to close and open PR so that the checks run correctly.

@DiogoMarques29 DiogoMarques29 merged commit 178a15a into infoportugal:master Jul 18, 2024
61 checks passed
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.

3 participants