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

flush($entity) is deprecated, and duplicates updates and logs #40

Open
Nils-1st-retail opened this issue Feb 5, 2019 · 2 comments
Open

Comments

@Nils-1st-retail
Copy link

According to doctrine/orm#6915
$em->flush($entity) shouldn't be used anymore since it will perform a full flush.

This currently causes duplicate updates, and entries in the audit log if you update multiple entities in the same flush.
The first entity is only updated once and one audit log. The second entity twice. 3rd 3 times and so on.

Further more $em->flush($entity) will be removed with doctrine v3.0.

I'm currently running on Doctrine v2.9 with EasuAuditBundle v1.4.9

@ronisaha
Copy link
Member

ronisaha commented Feb 5, 2019

Could you please explain more. What are you doing? what are the expected behavior? What are you getting currently?
Are you getting duplicate log for single entity? If you are doing a create action and a update on same request, it is obvious , you will get two log - one for create and another for update. As doctrine changing single entity update, I may have to change logger code, otherwise on flush command of log object, other pending query would also be executed. other than that there is nothing we can do.

@Nils-1st-retail
Copy link
Author

Nils-1st-retail commented Feb 6, 2019

I update 3 entities in the same flush.
The first entity run updated and gets a single log entry.
Then because doctrine have changed the ->flush($entity) to flush everything the other 2 entities are flushed again.
So for the 2nd entity I get 2 update queries run, and 2 log entries, along with another full flush causing the 3rd entity to be flushed 3 times getting 3 identical update queries, and the 3 logs matching those updates.
Resulting in 9 update queries being run instead of the expected 3, along with 9 log entries resulting in 18 queries vs the expected 6 (3 of each).

It's the problem you are describing in the end, is already happening on doctrine v2.9 (might be on earlier versions too).

As a workaround I have split my updates into single flushes to avoid the duplicates, but that is inefficient for larger flushes, but still more efficient than duplicating all pending queries once for each log.

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

No branches or pull requests

2 participants