Repository navigation
Reflect a model's relation methods once per class - #268
Closed
JonasPardon wants to merge 1 commit into
Closed
JonasPardon wants to merge 1 commit into
JonasPardon wants to merge 1 commit into
Conversation
getRelationMethods() only reused its result once a relation method had been resolved, so a model whose relations are all array-defined was reflected again on every relation lookup. Once a single method had been resolved, it returned just that method. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
bennothommo
approved these changes
Oct 23, 2026
Member
|
Fixes wintercms/winter#1581 |
bennothommo
added a commit
that referenced
this pull request
Oct 26, 2026
Instead of repeating reflection on the model class each time a relation is checked, this does one pass on the first model relation call, and caches the result. Dynamic methods are still checked live each time. Resolves wintercms/winter#1581 Replaces #268 Thanks to @JonasPardon for initial fix.
Author
|
Replaced by #270 |
LukeTowers
pushed a commit
that referenced
this pull request
Nov 4, 2026
Instead of repeating reflection on the model class each time a relation is checked, this does one pass on the first model relation call, and caches the result. Dynamic methods are still checked live each time. This also resolves a bug where an initial hasRelation call would cache a single relation and cause other relation methods (such as getDefinedRelations) to only return the single relation. Resolves: wintercms/winter#1581 Replaces: #268
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.
getRelationMethods()only reuses its result once$resolvedRelationMethodshas an entry for the class. That entry is only written when a method resolves to a relation, so:$belongsTo,$hasMany, …) never gets an entry. Every call runsReflectionClass::getMethods()again.getRelationType()calls it once per relation type, so this happens about ten times per lookup.getRelationType('messages')) writes a partial entry. After that,getRelationMethods()returns only['messages']instead of every relation method.The change keeps the methods found by the reflection scan per class in
$scannedRelationMethodsand returns those. Extension and dynamic methods are still checked on every call, as before.Phone::getRelationType('author')×1000 in the test suite goes from 139 ms to 1.2 ms. On a production Winter site onwip/1.3, this function took about 25% of the render time of a page with many models. That page went from 1040 ms to 676 ms with only this change.getRelationMethods(), and a class without relation methods is reflected once. Both fail without the change.🤖 Generated with Claude Code