API Platform version(s) affected: 2.5.4
Description
On a collection operation with filtering, FilterEagerLoadingExtension transforms the query into a wrapped subquery: ... WHERE o.id IN( <original query> ). When doing so, it duplicates joins from the original query and keeps them on the wrapping query in the result.
Though some of those joins might have been added by EagerLoadingExtension. Duplicating them is not necessary as they don't change the result (the retrieved resources will be the same). They should appear in the wrapping query, but not in the wrapped one. With many extra joins, this can lead to performance penalty. In my case I'm not sure yet whether the performance penalty was a database issue (e.g. missing index) but preventing joins duplication fixed it.
How to reproduce
Use a filter on a collection operation of a resource that has many eager loaded relations.
Possible Solution
To prevent the duplication, I changed the priority attribute of the api_platform.doctrine.orm.query_extension.collection tag of EagerLoadingExtension: I set it to -18 instead of -8 so it runs after FilterEagerLoadingExtension. This did not break any test on the project but I don't know all the implications of such change. Should the tag be updated in api-platform/core? If so, maybe FilterEagerLoadingExtension could be merged into EagerLoadingExtension?
API Platform version(s) affected: 2.5.4
Description
On a collection operation with filtering,
FilterEagerLoadingExtensiontransforms the query into a wrapped subquery:... WHERE o.id IN( <original query> ). When doing so, it duplicates joins from the original query and keeps them on the wrapping query in the result.Though some of those joins might have been added by
EagerLoadingExtension. Duplicating them is not necessary as they don't change the result (the retrieved resources will be the same). They should appear in the wrapping query, but not in the wrapped one. With many extra joins, this can lead to performance penalty. In my case I'm not sure yet whether the performance penalty was a database issue (e.g. missing index) but preventing joins duplication fixed it.How to reproduce
Use a filter on a collection operation of a resource that has many eager loaded relations.
Possible Solution
To prevent the duplication, I changed the
priorityattribute of theapi_platform.doctrine.orm.query_extension.collectiontag ofEagerLoadingExtension: I set it to-18instead of-8so it runs afterFilterEagerLoadingExtension. This did not break any test on the project but I don't know all the implications of such change. Should the tag be updated inapi-platform/core? If so, maybeFilterEagerLoadingExtensioncould be merged intoEagerLoadingExtension?