-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Deprecate EntityManager::flush with $entity argument #8459
Comments
Hello @beberlei :) Can you give me another tip, how can I solve my issue when flushing objects as parameters, will it be deprecated? I have one huge table with Orders. It's used in a lot of places in the system. Normally we use If I pass Order object to flush - whole execution take more or less 60s. Without that 1200s, because size of unitOfWork is too huge. Explicit change tracking policy can be apply on whole entity level only? I can't change this because it is used in too many places. Can I apply the policy only in one action? or one command? Greetings from Poland :) |
@beberlei @Ocramius any news on this deprecation ? We should be able to do a specific data change at least in a new transaction without flushing the whole changes.
I'm probably wrong but adding a property on EntityManager $savedUnitOfWork to store the current uof, instantiate a new empty one seems pretty simple imho :
|
+1 |
It already possible, if I right understood the linked doc. Old: $em->persist($entity);
$em->flush($entity); New: $em->persist($entity);
$em->flush(); |
@Fedik I see a problem with it: |
That correct, and that why you have to be sure all your Entities is set to DEFERRED_EXPLICIT(or NOTIFY) and that you call |
Is it possible to set ChangeTrackingPolicy per script execution? I am happy enough that whole app is set to Deferred Implicit, but for data upload from excel files I need Deferred Explicit, removing of that option will add me a lot of work (I will have to check whole app where we have missing persist) |
Fixed via #9485. |
There were any discussion about that? This change makes many scripts in batches last way much longer. And what is even worse, since this change you can no longer be sure which things are flushed. If I have to be honest, I don't really like this change. |
@kgasienica its deprecated yes, but we also plan to introduce an alternative that is better. Just keep using the deprecated way until then |
Okay, thank you. It is really breaking-change thing that is changing the way entities have to be managed in our applications. |
@beberlei any information on the new alternative please ? |
@beberlei @greg0ire it seems that the alternative was this one but @Ocramius won't work on it anymore by lack of time I guess. Still same approach ? or an other is considered ? |
there are probably cases that I can't think of where this wouldn't work, but thought to share it incase it could be useful. If the existing flush method was renamed to something like
|
@phpws Please don't do that :-) |
@beberlei ok, I didn't in the end, don't worry :-D, I take it that would have adverse affects on other things, performance for one would probably be a problem on large projects with huge sets of scheduledEntites collections, also it doesn't account for updates. |
@beberlei @greg0ire you released the doctrine 3.0 RC1, congrats, what about this BC BREAK there's still no alternative ? |
@wadjeroudi I'm told that using |
So, the real way to work with it normally, is to make handwritten queries, like in old times?
I mean, sometimes you need to do something under the hood - write do database log, cache some items, but you don't wan't to ruin the main business logic. |
So how can we insert/flush only one Entity e.g. I need a record ID in multiple places but based on this record some other entities could change so I don't want to inc the server load to insert one and update the others Then again update several records so updating at least twice i would insert one do the stuff and update once.... |
And... where is an alternative? |
The method
EntityManager::flush
has an optional argument $entity (either accepting a single entity or array of entities) that when passed are the only set of entities considered in compute changeset operation. The idea originally was to allow more performant flush operations when a lot of entities are in the identity map.However due to restrictions in how the UnitOfWork operates, it had to also "flush" other entities sometimes that were not passed to
flush
, making the operation inconsistent.As such we decided to deprecate this approach to flushing and only allow a full flush for now.
Alternative: If you want to keep the set of entities small that flush operates on, you could decide to use the explicit change tracking policy for an entity instead of the implicit one. https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/reference/change-tracking-policies.html
The text was updated successfully, but these errors were encountered: