8000 bug #35252 [Serializer] Fix cache in MetadataAwareNameConverter (bast… · symfony/symfony@9589dee · GitHub
[go: up one dir, main page]

Skip to content

Commit 9589dee

Browse files
committed
bug #35252 [Serializer] Fix cache in MetadataAwareNameConverter (bastnic)
This PR was merged into the 4.4 branch. Discussion ---------- [Serializer] Fix cache in MetadataAwareNameConverter | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | ref #35085 | License | MIT | Doc PR | `isset` is used to test existence of values that is `null` by default, which result to always bypass the cache and force to do the calculation all the time. This is a serious perf improvement in prod mode for an api. ![image](https://user-images.githubusercontent.com/84887/71933779-38c3ae80-31a3-11ea-8871-8e57cec87a89.png) ![image](https://user-images.githubusercontent.com/84887/71933675-074ae300-31a3-11ea-8e84-7adad3e6c96f.png) Commits ------- 6449f92 [Serializer] Fix cache in MetadataAwareNameConverter
2 parents b9cc0c8 + 6449f92 commit 9589dee

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function normalize($propertyName, string $class = null, string $format =
4747
return $this->normalizeFallback($propertyName, $class, $format, $context);
4848
}
4949

50-
if (!isset(self::$normalizeCache[$class][$propertyName])) {
50+
if (!\array_key_exists($class, self::$normalizeCache) || !\array_key_exists($propertyName, self::$normalizeCache[$class])) {
5151
self::$normalizeCache[$class][$propertyName] = $this->getCacheValueForNormalization($propertyName, $class);
5252
}
5353

@@ -64,7 +64,7 @@ public function denormalize($propertyName, string $class = null, string $format
6464
}
6565

6666
$cacheKey = $this->getCacheKey($class, $context);
67-
if (!isset(self::$denormalizeCache[$cacheKey][$propertyName])) {
67+
if (!\array_key_exists($cacheKey, self::$denormalizeCache) || !\array_key_exists($propertyName, self::$denormalizeCache[$cacheKey])) {
6868
self::$denormalizeCache[$cacheKey][$propertyName] = $this->getCacheValueForDenormalization($propertyName, $class, $context);
6969
}
7070

@@ -78,7 +78,7 @@ private function getCacheValueForNormalization(string $propertyName, string $cla
7878
}
7979

8080
$attributesMetadata = $this->metadataFactory->getMetadataFor($class)->getAttributesMetadata();
81-
if (!isset($attributesMetadata[$propertyName])) {
81+
if (!\array_key_exists($propertyName, $attributesMetadata)) {
8282
return null;
8383
}
8484

@@ -93,7 +93,7 @@ private function normalizeFallback(string $propertyName, string $class = null, s
9393
private function getCacheValueForDenormalization(string $propertyName, string $class, array $context): ?string
9494
{
9595
$cacheKey = $this->getCacheKey($class, $context);
96-
if (!isset(self::$attributesMetadataCache[$cacheKey])) {
96+
if (!\array_key_exists($cacheKey, self::$attributesMetadataCache)) {
9797
self::$attributesMetadataCache[$cacheKey] = $this->getCacheValueForAttributesMetadata($class, $context);
9898
}
9999

0 commit comments

Comments
 (0)
0