Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dfd691f

Browse filesBrowse 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 dfd691f
Copy full SHA for dfd691f

File tree

1 file changed

+4
-4
lines changed
Filter options

1 file changed

+4
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php
+4-4Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.