When adding or changing nodes using set with keep item order on, the new node was always added with order = 0 (first position). This destroyed the original order. It also made it impossible to generate a JSON where the nodes should to be in a specific order, which is the expectation when setting "keep item order".
The fix preserves the order when changing nodes and also counts up the order when adding new nodes (so they keep in the order they where inserted).
Technical background:
Keep item order is based on secondary index of the nodes table. However, if all order values are 0, then the sort order is not well defined and does not necessarily match the order in which nodes where inserted.
Hi Marc, sorry I completely missed this PR. Merging. But there is a small issue in edge cases with external jsons, I mentioned it in a comment, maybe will fix later myself
When adding or changing nodes using set with keep item order on, the new node was always added with order = 0 (first position). This destroyed the original order. It also made it impossible to generate a JSON where the nodes should to be in a specific order, which is the expectation when setting "keep item order".
The fix preserves the order when changing nodes and also counts up the order when adding new nodes (so they keep in the order they where inserted).
Technical background:
Keep item order is based on secondary index of the nodes table. However, if all order values are 0, then the sort order is not well defined and does not necessarily match the order in which nodes where inserted.