Skip to content

Commit 199fda6

Browse files
committed
[Serializer] Fix cache in MetadataAwareNameConverter
`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 calculate all the time. This is a critical perf improvement in prod mode for an api. Ref #35085
1 parent b9cc0c8 commit 199fda6

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy