feat(doctrine): eagerly load translations of translatable resources - #88
Merged
Merged
Conversation
Reading a translated field resolves the locale through matching() on the EXTRA_LAZY translations collection, which issues one query per entity per locale: listing N resources costs N extra queries (Locastic#10). Add a TranslationsEagerLoadingExtension (experimental) that fetch-joins the translations of TranslatableInterface resources on collection and item queries, so the collections come back initialized and matching() filters in memory. All locales are joined, not only the current one: a locale-constrained fetch join would mark the collection initialized with a subset, breaking fallback-locale reads and the translations group. Locale-constrained joins added by filters are ignored by the guard for the same reason, and get a dedicated unconstrained join next to them. The new eager_load_translations option (default true) restores lazy loading when set to false. The service is registered only when the api-platform Doctrine ORM extension interfaces exist, since api-platform/symfony does not require the doctrine-orm bridge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TranslationsEagerLoadingExtension(experimental) +eager_load_translationsoptionProblem
Reading a translated field resolves the locale through
matching()on theEXTRA_LAZYtranslations collection, which issues one query per entity per locale: listing N resources costs N extra queries (#10).Changes
TranslationsEagerLoadingExtension(experimental): fetch-joins the translations ofTranslatableInterfaceresources on collection and item queries, so the collections come back initialized andmatching()filters in memory.translationsserialization group. Locale-constrained joins added by filters are ignored by the guard for the same reason, and get a dedicated unconstrained join next to them.eager_load_translationsoption (defaulttrue); setfalseto restore lazy loading.api-platform/symfonydoes not require thedoctrine-ormbridge); tag priorities mirror core'sEagerLoadingExtension(collection -18, item -8).Verification
?locale=,?groups[]=translations, PATCH merge and fallback reads unchanged; invalid config rejected at compile time.