core icon indicating copy to clipboard operation
core copied to clipboard

feat(doctrine): optimize EagerLoadingExtension to skip unnecessary joins

Open bizley opened this issue 8 months ago • 9 comments

Q A
Branch? main for features / current stable version branch for bug fixes
Tickets Closes #7036 (WIP)
License MIT
Doc PR api-platform/docs#... (not yet)

This is a quick check if anything breaks after this optimization. Tests TBD

bizley avatar Mar 21 '25 10:03 bizley

interetsing, there's only one failure at features/doctrine/eager_loading.feature:64 I guess it's because of the property filter (it adds attributes to the serializer groups), maybe that the code needs a small adjustment?

soyuka avatar Mar 21 '25 19:03 soyuka

Ok, looks like I made it green. Now to make tests proving it generates fewer joins. Should I proceed? Any tips?

bizley avatar Mar 22 '25 13:03 bizley

really nice, the easiest is to add a feature inside:

https://github.com/api-platform/core/blob/main/features/doctrine/eager_loading.feature

Fixtures are located at https://github.com/api-platform/core/tree/main/tests/Fixtures/TestBundle/Entity

Thanks!

soyuka avatar Mar 25 '25 09:03 soyuka

Just for an update on this - we encountered heavy db problems in our app for some custom filters execution so I'm checking if this is just a problem on our side or this change would do that for everyone, which of course we really don't want to happen.

bizley avatar Apr 02 '25 16:04 bizley

first guess: FilterEagerLoadingExtension

did you analyse the queries? do you need many joins?

soyuka avatar Apr 02 '25 18:04 soyuka

Probably, yes, this one. We have changed prio of EagerLoadingExtension to -19 and FilterEagerLoadingExtension to -18. Generated query had two nested SELECTs so terrible in general. Analyzing.

bizley avatar Apr 03 '25 08:04 bizley

yes its also why we recommend to define your own queries as we're quite limited in how to we can generate automatic queries, you can also use the LinksHandler for these kind of use cases.

soyuka avatar Apr 03 '25 10:04 soyuka

status? should we merge this?

soyuka avatar Apr 10 '25 12:04 soyuka

Give me few more days till the end of week ;)

bizley avatar Apr 10 '25 12:04 bizley