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

Updating node updated_at causes unwanted side-effects #30

Open
imade-nl opened this issue Sep 29, 2016 · 3 comments
Open

Updating node updated_at causes unwanted side-effects #30

imade-nl opened this issue Sep 29, 2016 · 3 comments
Assignees
Labels

Comments

@imade-nl
Copy link

When I want to touch the timestamp of a nested Model it looses it's depth.

I have a nested Page model that has a relationship with a Content model.
When I update the Content model I want to touch the updated_at timestamp of the Page model.
This all works fine with protected $touches = ['page']; in the Content model, but as a bonus I get a set of extra queries that also set the depth off the Page model to zero.

-
UPDATE `contents` set `fields` = '{\"leader\":[{\"file\":\"2\",\"description\":\"\"}],\"about_titel\":\"\",\"about_tekst_1\":\"\",\"about_tekst_2\":\"\",\"contact_titel\":\"\",\"contact_tekst\":\"\"}', `updated_at` = '2016-09-29 23:52:45' WHERE `id` = '129'
UPDATE `pages` set `updated_at` = '2016-09-29 23:52:45' WHERE `pages`.`id` = '118'
SELECT * FROM `pages` WHERE `pages`.`id` = '118' LIMIT 1
SELECT * FROM `pages` WHERE `pages`.`id` = '118' LIMIT 1
SELECT max(`rgt`) as aggregate FROM `pages`
SELECT * FROM `pages` WHERE `pages`.`id` = '118' LIMIT 1
UPDATE `pages` set `depth` = '0', `updated_at` = '2016-09-29 23:52:45' WHERE `id` = '118' ORDER BY `pages`.`lft` ASC
1.060 m

Is there some kind of event that triggers these last 5 queries?

@gazsp
Copy link
Owner

gazsp commented Feb 8, 2017

Sorry for the late reply.

I've had a quick look at this, and I think it's caused by the saved event being caught in Baum\Node, which calls moveToNewParent then setDepth. It's obviously a bug, as we shouldn't be updating anything 'node-related' just because a time stamp changes.

I'll need to look in this more and implement a fix.

@gazsp gazsp added the bug label Feb 8, 2017
@gazsp gazsp changed the title Touching Parent Timestamps Updating node updated_at causes unwanted side-effects Feb 8, 2017
@gazsp gazsp self-assigned this Feb 8, 2017
@imade-nl
Copy link
Author

imade-nl commented Feb 9, 2017

Thanks for your response!
I hope you find a solution, it would make cache-busting a lot easyer. :-)

@beneberle
Copy link

I ran across this issue, too, and for anyone else needing a fix, I changed the default $moveToNewParentId from null to false and it seemed to solve it for me. This is line 67 in
src/Baum/Node.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants