Closed mbayane closed 3 months ago
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!
update_descendants
Hello @DiogoMarques29,
Thanks for your reply and suggestions.
i will update it shortly
Regards
Hello @DiogoMarques29,
Changes pushed
Thanks
Had to close and open PR so that the checks run correctly.
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)