Bugfix/filling gaps and eager loading - #19318
Draft
i-just wants to merge 3 commits into
Draft
Conversation
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.
Description
Issues:
maintainHierarchyturned on is different depending on whether you don’t eager-load vs eager-load with.with()vs lazy eager-load with.eagerly()vs lazy eager-load with.eagerly()with alias (.eagerly('myAlias')).Steps to reproduce:
with,eagerlyandeagerly('myAlias')and check the number of db calls for eachmaintainHierarchyResults before this PR:
Results with this PR:
maintainHierarchyoff, the count and results are the samemaintainHierarchyon, but no gaps to fill, the.with()and.eagerly('myAlias')require the same number of queries to achieve the same results;.eagerly()requires more queries than before, and the higher count compared to.with()and.eagerly('myAlias')comes from multiple field layout providersmaintainHierarchyon, and gaps to fill, the.with()and.eagerly('myAlias')require the same number of queries to achieve the same results;.eagerly()requires more queries than before, and the higher count compared to.with()and.eagerly('myAlias')comes from multiple field layout providers and the fact that it “re-triggers its full eager-loading computation once per distinct field-layout provider that shares the field”More info:
ElementQuery::EVENT_BEFORE_PREPARE(similar to whatBaseRelationFielddoes with multi-instance relation fields and joining in the relations table values)maintainHierarchyonNew recommendation:
maintainHierarchyturned on) used across multiple field layout providers (e.g. multiple entry types), it’s advisable to pass an alias to the.eagerly()method to optimise the number of queries needed to fulfil the taskIf anyone has a better idea on how to fix this, LMK.
An argument could also be made that since we’re not filling in the gaps for other Relation fields that support maintaining hierarchy (e.g. Entries) and since
.with()was not filling in the gaps before, then.eagerly()shouldn’t do it either. If that’s what we want to go with, LMK and I can adjust.Related issues
n/a; original discrepancy in the number of queries came from @tommysvr