-
-
Notifications
You must be signed in to change notification settings - Fork 921
fix normalizer cache key generation #1894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -213,7 +216,7 @@ private function getRelationIri($rel): string | |||
* | |||
* @return bool|string | |||
*/ | |||
private function getHalCacheKey(string $format = null, array $context) | |||
private function getCacheKey(string $format = null, array $context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert those changes? Reusing the name of a method (even private) defined in a parent class is misleading and trigger warning in some analysis tools (PHP EA inspection IIRC)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Codecov Report
@@ Coverage Diff @@
## 2.2 #1894 +/- ##
============================================
+ Coverage 96.47% 96.47% +<.01%
- Complexity 2600 2602 +2
============================================
Files 191 191
Lines 6526 6534 +8
============================================
+ Hits 6296 6304 +8
Misses 230 230
Continue to review full report at Codecov.
|
if (false !== $context['cache_key'] && isset($this->componentsCache[$context['cache_key']])) { | ||
return $this->componentsCache[$context['cache_key']]; | ||
$class = \get_class($object); | ||
$cacheKey = $class.'-'.$context['cache_key']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$class seems used only one time
@@ -221,8 +223,11 @@ protected function isAllowedAttribute($classOrObject, $attribute, $format = null | |||
*/ | |||
private function getComponents($object, string $format = null, array $context) | |||
{ | |||
if (isset($this->componentsCache[$context['cache_key']])) { | |||
return $this->componentsCache[$context['cache_key']]; | |||
$class = \get_class($object); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$class seems used only one time
@@ -99,8 +102,10 @@ protected function getAttributes($object, $format = null, array $context) | |||
*/ | |||
private function getComponents($object, string $format = null, array $context) | |||
{ | |||
if (false !== $context['cache_key'] && isset($this->componentsCache[$context['cache_key']])) { | |||
return $this->componentsCache[$context['cache_key']]; | |||
$cacheKey = \get_class($object).'-'.$context['cache_key']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We know the object class in the normalize
method right? Could we pass the information to this function to avoid calling get_class
? Might be a micro-optimization though. (same below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\get_class
is transformed in opcode, it's almost costless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For info I've copied the method used in core symfony, which is to add the class here
we good here? |
Thanks @bendavies. All your work regarding performance is very appreciated! |
…keys fix normalizer cache key generation
Cache keys were being regenerated even if they were already present. this disabled caching when serializing resources which have already been serialized.
https://blackfire.io/profiles/compare/e4646b66-8700-4ac9-b36e-9de700dc5b03/graph