xiidea / EasyAuditBundle

A Symfony Bundle To Log Selective Events
http://xiidea.github.io/EasyAuditBundle/
MIT License
89 stars 22 forks source link

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

Open Nils-1st-retail opened 5 years ago

Nils-1st-retail commented 5 years ago

According to https://github.com/doctrine/orm/issues/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 commented 5 years ago

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 commented 5 years ago

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.