Skip to content

Sort the children of a parent node after either deleting or moving a child node#17315

Merged
georgebid merged 1 commit intoumbraco:contribfrom
manutdkid77:temp/17273
Nov 7, 2024
Merged

Sort the children of a parent node after either deleting or moving a child node#17315
georgebid merged 1 commit intoumbraco:contribfrom
manutdkid77:temp/17273

Conversation

@manutdkid77
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

This fixes #17273

Description

  • When a new document node A is created under a parent node, it is assigned a SortOrder value of 0.
  • Now if you created another document node B under the parenr node, it is assigned a SortOrder value of 1.
  • Now delete node A
  • Create a new node C, here the SortOrderExists looks to find any item with sortOrder as 0.
  • But the SortOrderExists can't find such an item with SortOrder as 0, so it returns false, and this results in setting the SortOrder as 0
  • My solution is to recalculate the Sort after deletion or move operation of a document node.

@github-actions
Copy link

github-actions bot commented Oct 18, 2024

Hi there @manutdkid77, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@emmagarland
Copy link
Collaborator

@manutdkid77  thanks a lot for your PR to fix the issue #17273

One of us Core Collabs team will review it soon 🙌

@nul800sebastiaan
Copy link
Member

Hi there @manutdkid77! Thanks again and sorry for the delay, we'll get to it!

Just a hint: as you may know, this PR qualifies for Umbraco's Hacktoberfest participation for which you can earn rewards.
If you were to make 1 more contribution in the next few days, would be great to see your contributions qualify! You can do it.. 😉

@manutdkid77
Copy link
Contributor Author

Thank you @nul800sebastiaan , I'll look to contribute another one 🙂

@georgebid georgebid merged commit 6705de0 into umbraco:contrib Nov 7, 2024
@georgebid
Copy link
Contributor

Hey, @manutdkid77 thanks again for your PR! This has now been tested and works as expected - therefore I have merged this in 😄

nul800sebastiaan added a commit that referenced this pull request Nov 12, 2024
…r moving its child content (#17315)"

This reverts commit 6705de0.
@nul800sebastiaan
Copy link
Member

Hey there @manutdkid77! Thanks for the contribution and I'm sorry to have to do this, but I have reverted (b00c84a) this merge. The solution is (almost) never to do a sort operation. Sorting can be a heavy operation and it is entirely possible that you'll accidentally end up sorting (and re-sorting and re-sorting) hundreds, thousands, or more nodes in the database which can lead to a huge performance bottleneck.

You had the cause of the issue narrowed down pretty closely but you should have checked what was actually happening in the database. Node B actually has a perfectly fine sortOrder of 0 but the query includes the nodeObjectType, which in SQLite apparently is case-sensitive.

As you can see, this query works:

image

However, the actual query that is being sent in uses the lower case for nodeObjectType:

image

This yields no results and therefore SortOrderExists returns false, while it should be true.

I can update the query by casting the column result and the value to UPPER() or LOWER():

image

But I don't know if that's the correct solution, I'm going to have to get some input from the team.

@nul800sebastiaan
Copy link
Member

FYI: my team member Sven made a new PR for this: #17517

@umbrabot
Copy link

umbrabot commented Dec 4, 2024

Hi there @manutdkid77!

First of all: A big #H5YR for making an Umbraco related contribution during Hacktoberfest! We are very thankful for the huge amount of PRs submitted, and all the amazing work you've been doing 🥇

Due to the amazing work you and others in the community have been doing, we've had a bit of a hard time keeping up. 😅 While all of the PRs for Hacktoberfest might not have been merged yet, you still qualify for receiving some Umbraco swag, congratulations! 🎉

In the spirit of Hacktoberfest we've prepared some exclusive Umbraco swag for all our contributors - including you!
This year's swag is a custom designed notebook and custom Umbraco Hacktoberfest sticker:

image

As an alternative choice, you can opt-out of receiving anything and ask us to help improve the planet instead by planting a tree on your behalf. 🌳

Receive your swag or plant a tree! 👈 Please follow this link to fill out and submit the form, before December 25th, 2024, 23:59:00 UTC.

Following this date we'll be sending out all the swag, but please note that it might not reach your doorstep for a few weeks/months, so please bear with us and be patient 🙏

The only thing left to say is thank you so much for participating in Hacktoberfest! We really appreciate the help!

Kind regards,
The various Umbraco teams.

@manutdkid77
Copy link
Contributor Author

@nul800sebastiaan No worries, you are absolutely right. I should have considered the performance implications, especially when working on a large content tree. Thank you for the detailed explanation, it has helped me understand more about how the sorting works behind the scenes. 🙂

@nul800sebastiaan nul800sebastiaan added the release/no-notes Not directly part of the release (updating README, build scripts, tests, etc.) label Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community/pr hacktoberfest/contrib-2024 hacktoberfest-accepted release/no-notes Not directly part of the release (updating README, build scripts, tests, etc.) type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Moving item to bin doesn't update its siblings sort order

6 participants