-
-
Notifications
You must be signed in to change notification settings - Fork 921
Fix duplicate data in Eager loads relations #2183
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
Conversation
@@ -232,6 +232,8 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt | |||
|
|||
$this->joinRelations($queryBuilder, $queryNameGenerator, $mapping['targetEntity'], $forceEager, $fetchPartial, $associationAlias, $options, $normalizationContext, 'leftJoin' === $method, $joinCount, $currentDepth); | |||
} | |||
|
|||
$queryBuilder->getQuery()->getResult(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhhh but this will execute the query multiple time right? I don't get the point.
May we have a test illutrating the bug in api-platform/api-platform#799 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you're talking about the comment saying: // result is discarded (this is just re-hydrating the collections)
. May you add a comment like this because it's really confusing if you're not familiar with doctrine internals...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@soyuka sure, also I will also add tests to cover this
thanks @ilicmsreten ! |
Hi, this PR generate an issue when getting data from a table containing lots of data because a query is generated and hydration is done without any LIMIT. This is linked to the fact the PaginationExtension is not yet applied to the query builder. As you can see in https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/CollectionDataProvider.php, when calling For me |
Or if you wants to keep the multi step hydration it should be done after all other extensions... |
We will definitely look into this asap because performances could be improved. Sorry about the mistake, we're in the process of tagging |
Ok thanks, in fact it's more than just a performance issue. For example I always get memory limit issues (error 500) when getting a limited list of items from a table containing a lot of data (more than 50000). |
@raziel057 we tagged 2.3.3 without this patch and we'll try to improve it taking your inputs into consideration before it gets merged! Thanks! |
Thank you very much for your fast action! |
@soyuka fix is reverted, but I'm here because of original issue ))) I have doctrine collections with the same elements inside. Can you recommend a fix for this? |
I'm really not sure how this is possible, would you mind giving me a way to reproduce? /edit: gonna look into api-platform/api-platform#799 |
@errogaht the solution is to simply disable the eager loading feature or build your own query. I'm really not sure how we could fix this otherwise... For the api-platform/api-platform#799 example: /**
* @ApiResource(
* attributes={"normalization_context"={"groups"={"order_read", "customer_read", "address_read"}}, "force_eager"=false}
* )
* @ORM\Entity
* @ORM\Table(name="`order`")
*/
class Order
{
} |
this is the query what EagerLoadingExtension generating. |
This PR is related to reported bug in api-platform/api-platform project.
So problem is caused because the same tables is joined multiple times ON same condition but with different aliases.
I find useful article by Marco Pivetta about Doctrine hydration where they said about coding multi-step hydration, that is used in PR.