[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
This commit is contained in:
parent
b9cc0c8985
commit
6449f9299c
@ -47,7 +47,7 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
|
|||||||
return $this->normalizeFallback($propertyName, $class, $format, $context);
|
return $this->normalizeFallback($propertyName, $class, $format, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(self::$normalizeCache[$class][$propertyName])) {
|
if (!\array_key_exists($class, self::$normalizeCache) || !\array_key_exists($propertyName, self::$normalizeCache[$class])) {
|
||||||
self::$normalizeCache[$class][$propertyName] = $this->getCacheValueForNormalization($propertyName, $class);
|
self::$normalizeCache[$class][$propertyName] = $this->getCacheValueForNormalization($propertyName, $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$cacheKey = $this->getCacheKey($class, $context);
|
$cacheKey = $this->getCacheKey($class, $context);
|
||||||
if (!isset(self::$denormalizeCache[$cacheKey][$propertyName])) {
|
if (!\array_key_exists($cacheKey, self::$denormalizeCache) || !\array_key_exists($propertyName, self::$denormalizeCache[$cacheKey])) {
|
||||||
self::$denormalizeCache[$cacheKey][$propertyName] = $this->getCacheValueForDenormalization($propertyName, $class, $context);
|
self::$denormalizeCache[$cacheKey][$propertyName] = $this->getCacheValueForDenormalization($propertyName, $class, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$attributesMetadata = $this->metadataFactory->getMetadataFor($class)->getAttributesMetadata();
|
$attributesMetadata = $this->metadataFactory->getMetadataFor($class)->getAttributesMetadata();
|
||||||
if (!isset($attributesMetadata[$propertyName])) {
|
if (!\array_key_exists($propertyName, $attributesMetadata)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
|
|||||||
private function getCacheValueForDenormalization(string $propertyName, string $class, array $context): ?string
|
private function getCacheValueForDenormalization(string $propertyName, string $class, array $context): ?string
|
||||||
{
|
{
|
||||||
$cacheKey = $this->getCacheKey($class, $context);
|
$cacheKey = $this->getCacheKey($class, $context);
|
||||||
if (!isset(self::$attributesMetadataCache[$cacheKey])) {
|
if (!\array_key_exists($cacheKey, self::$attributesMetadataCache)) {
|
||||||
self::$attributesMetadataCache[$cacheKey] = $this->getCacheValueForAttributesMetadata($class, $context);
|
self::$attributesMetadataCache[$cacheKey] = $this->getCacheValueForAttributesMetadata($class, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user