Repository navigation
Limit combined attachment eager loading to requested fields - #678
Merged
daftspunk merged 4 commits intoSep 24, 2026
Merged
Conversation
samuelpatro
marked this pull request as ready for review
September 18, 2026 07:42
Member
|
Wow! 🤯 Thanks |
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.
Eager-loading one attachment field currently fetches every attachment for the selected owners, then filters the hydrated models by field. An entry with one cover and 100 gallery files therefore hydrates 101 file records for
with('cover').Restrict the combined attachment query to the requested fields that share the same related model, while keeping one query for multiple fields. The combined result cache is reset at the start of each eager-load pass so a reused builder loads the correct owners and fields. Scoped/conditional relations,
combineEager => false, and first-constraint behavior are preserved.10 regression tests cover cover-only hydration (101 → 1 file, one attachment query), multiple owners and fields, distinct related classes, opt-outs, nested loads, custom constraints, relation hooks, and reused builders. Full suite on PHP 8.4: 240 tests, 1493 assertions.
Rechecked on 2026-09-18 with PHP 8.4 / SQLite. Seven samples of ten warm cover-only loads (fixture setup excluded): with 100 unrelated gallery files, hydrated files drop from 101 to 1 and median time from 0.618 ms to 0.100 ms; with 1000 gallery files, from 1001 to 1 and 5.740 ms to 0.130 ms. Both versions issue two total queries (owner plus attachments). These are local illustrative timings; work-count tests are the regression gate. Full suite remains 240 tests / 1493 assertions.
Rechecked after the 2026-09-21 upstream merge: qualified the requested-field filter so eager constraints joining another table with a
fieldcolumn remain valid. The joined-query regression fails before the fix and passes after it, retaining one attachment query. PHP 8.4 branch suite: 242 tests / 1501 assertions; one pre-existing risky test without assertions. Combined integration with current 4.x and all seven open PRs passes 318 tests / 1762 assertions after retaining both sides of two merge conflicts (DbDatasource tests and Database Builder methods). This combined checkout is validation only; other PRs and 4.x were not merged into this branch.