Answer the question
In order to leave comments, you need to log in
Why can the Nested Sets tree break?
Hello everyone
In the yii2 project, https://github.com/creocoder/yii2-nested-sets is connected for the users table, a referral program is implemented on the site. In addition to the main fields lft, rgt, depth and tree, the parent_id field has been added. When binding or updating users, the prepandTo() method is executed to move the user to another user.
And so there was a problem that sometimes there are situations when lft at some entity becomes more, than rgt.
There are suspicions that this occurs after saving the user entities in the admin panel, where all fields in the database are updated and if the parent is changed, then prepandTo is done for the old record, but it did not work out. After this error, the user tree is partially broken
. Has anyone encountered a similar one?
Answer the question
In order to leave comments, you need to log in
I will assume that it breaks when adding users at the same time.
Retrieving the tree structure in Nested sets is done with a single request, but changing it requires several operations. Theoretically, under a certain situation, there may be a simultaneous recalculation of different nodes.
Try using transactions to solve the problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question