Description
API Platform version(s) affected: 3.2.26
Description
I'm sorry if I'm wasting your time on this but I think I realized something that can be improved (or I'm not seeing/experiencing the issues I could cause).
I have noticed that EagerLoadingExtension (at least the Doctrine ORM version) is adding joins that are uncalled for based on the serialization groups that are set. I have added this small IF to make sure that associations not marked with at least one of the serialization groups configured for the operation are skipped.
How to reproduce
This is more of a POC here althouth tested on my app. The extension is adding joins in the query builder that are not needed based on the configured serialization groups.
Possible Solution
In this line I have added:
if (
isset($attributesMetadata[$association])
&& empty(
array_intersect(
$normalizationContext[AbstractNormalizer::GROUPS] ?? [],
$attributesMetadata[$association]->getGroups()
)
)
) {
// Skip this association if the current normalization groups do not include the association's groups
continue;
}
My generated queries are much thinner now, sometimes even cutting the number of joins in half.
Additional Context
I really don't believe you have not thought about it so I think there is a reason to not added this exclusion and just I don't see it. OR somehow this is valid and I can start working on PR for this.
I have a solid number of behat tests in my app but still not everything is covered so my confidence here is like 50-50. And I'm pretty sure I don't have some exotic use cases you need to cover but here is my shot.
Or there is some simple solution for what I try to fix, please let me know.
Thank you.