Repository navigation
Conversation
PrefetchBuffer grouped sources by argument hash, so each alias of a #[Prefetch] field ran its own prefetch, but stored the result by source alone. When one object selected the field twice with different arguments (`a: field(x: 1) b: field(x: 2)`), the second alias found the first alias's result and returned it. Results are now stored per source and argument hash, the same hash that groups the sources. storeResult(), hasResult(), getResult() and purgeResult() take the arguments and ResolveInfo as optional trailing parameters.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #845 +/- ##
============================================
- Coverage 95.72% 92.13% -3.60%
- Complexity 1773 2165 +392
============================================
Files 154 204 +50
Lines 4586 5757 +1171
============================================
+ Hits 4390 5304 +914
- Misses 196 453 +257 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
When one object selects a
#[Prefetch]field twice with different arguments, both aliases get the first alias's result:barreturnsfooJoeinstead ofbarJoe.PrefetchBuffergroups the sources by a hash of the arguments (and the operation), so each alias does run its own prefetch method. But it stores the prefetch result in aWeakMapkeyed by the source alone. When the second alias'sDeferredruns,hasResult($source)is already true from the first alias, soPrefetchDataParameterreturns that result without calling the prefetch method for the second argument set.Fix
PrefetchBufferstores results per source and per argument hash, using the samecomputeHash()that groups the sources.storeResult(),hasResult(),getResult()andpurgeResult()take$argumentsandResolveInfo|null $infoas optional trailing parameters, andPrefetchDataParameterpasses the field's arguments andResolveInfo.hasResult()usesarray_key_exists(), so anullprefetch result still counts as stored.Aliases with the same arguments still share one prefetch call and one result.
Compatibility
Callers of the result methods keep working: the new parameters are optional, and calls without them read and write the entry for an empty argument set. A subclass that overrides one of the four result methods would need the new parameters added to its signature.
Tests
EndToEndTest::testPrefetchingSameFieldWithDifferentArguments: two aliases ofrepeatNamewith different prefixes, plus a third alias sharing the first one's prefix. Fails onmaster(barreturnsfooJoe).PrefetchBufferTest::testResultsPerArguments: results stored, read and purged per argument set, including anullresult.PrefetchDataParameterTest::testResolveWithExistingResultstores its result with the arguments it resolves with.Run locally on PHP 8.5 with
composer updateandcomposer update --prefer-lowest: phpunit 731 OK, phpstan no errors, phpcs clean.