More optimizations around hydrators. Pretty much same performance, just better memory footprint (-0.25MB).
This commit is contained in:
parent
be94eb9d1f
commit
9cd16ec56a
@ -263,13 +263,14 @@ abstract class AbstractHydrator
|
||||
continue;
|
||||
}
|
||||
|
||||
$fieldName = $cacheKeyInfo['fieldName'];
|
||||
|
||||
switch (true) {
|
||||
case (isset($cacheKeyInfo['isNewObjectParameter'])):
|
||||
$fieldName = $cacheKeyInfo['fieldName'];
|
||||
$argIndex = $cacheKeyInfo['argIndex'];
|
||||
$objIndex = $cacheKeyInfo['objIndex'];
|
||||
$type = $cacheKeyInfo['type'];
|
||||
$value = $type->convertToPHPValue($value, $this->_platform);
|
||||
$argIndex = $cacheKeyInfo['argIndex'];
|
||||
$objIndex = $cacheKeyInfo['objIndex'];
|
||||
$type = $cacheKeyInfo['type'];
|
||||
$value = $type->convertToPHPValue($value, $this->_platform);
|
||||
|
||||
$rowData['newObjects'][$objIndex]['class'] = $cacheKeyInfo['class'];
|
||||
$rowData['newObjects'][$objIndex]['args'][$argIndex] = $value;
|
||||
@ -278,15 +279,15 @@ abstract class AbstractHydrator
|
||||
break;
|
||||
|
||||
case (isset($cacheKeyInfo['isScalar'])):
|
||||
$value = $cacheKeyInfo['type']->convertToPHPValue($value, $this->_platform);
|
||||
$type = $cacheKeyInfo['type'];
|
||||
$value = $type->convertToPHPValue($value, $this->_platform);
|
||||
|
||||
$rowData['scalars'][$cacheKeyInfo['fieldName']] = $value;
|
||||
$rowData['scalars'][$fieldName] = $value;
|
||||
break;
|
||||
|
||||
case (isset($cacheKeyInfo['isMetaColumn'])):
|
||||
$dqlAlias = $cacheKeyInfo['dqlAlias'];
|
||||
$fieldName = $cacheKeyInfo['fieldName'];
|
||||
$type = $cacheKeyInfo['type'];
|
||||
$dqlAlias = $cacheKeyInfo['dqlAlias'];
|
||||
$type = $cacheKeyInfo['type'];
|
||||
|
||||
// Avoid double setting or null assignment
|
||||
if (isset($rowData['data'][$dqlAlias][$fieldName]) || $value === null) {
|
||||
@ -298,17 +299,14 @@ abstract class AbstractHydrator
|
||||
$nonemptyComponents[$dqlAlias] = true;
|
||||
}
|
||||
|
||||
if ($type) {
|
||||
$value = $type->convertToPHPValue($value, $this->_platform);
|
||||
}
|
||||
|
||||
$rowData['data'][$dqlAlias][$fieldName] = $value;
|
||||
$rowData['data'][$dqlAlias][$fieldName] = $type
|
||||
? $type->convertToPHPValue($value, $this->_platform)
|
||||
: $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
$dqlAlias = $cacheKeyInfo['dqlAlias'];
|
||||
$fieldName = $cacheKeyInfo['fieldName'];
|
||||
$type = $cacheKeyInfo['type'];
|
||||
$dqlAlias = $cacheKeyInfo['dqlAlias'];
|
||||
$type = $cacheKeyInfo['type'];
|
||||
|
||||
// in an inheritance hierarchy the same field could be defined several times.
|
||||
// We overwrite this value so long we don't have a non-null value, that value we keep.
|
||||
@ -375,11 +373,9 @@ abstract class AbstractHydrator
|
||||
$dqlAlias = $cacheKeyInfo['dqlAlias'];
|
||||
$type = $cacheKeyInfo['type'];
|
||||
|
||||
if ($type) {
|
||||
$value = $type->convertToPHPValue($value, $this->_platform);
|
||||
}
|
||||
|
||||
$rowData[$dqlAlias . '_' . $fieldName] = $value;
|
||||
$rowData[$dqlAlias . '_' . $fieldName] = $type
|
||||
? $type->convertToPHPValue($value, $this->_platform)
|
||||
: $value;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -67,11 +67,7 @@ class ArrayHydrator extends AbstractHydrator
|
||||
*/
|
||||
protected function prepare()
|
||||
{
|
||||
$this->_isSimpleQuery = count($this->_rsm->aliasMap) <= 1;
|
||||
$this->_identifierMap = array();
|
||||
$this->_resultPointers = array();
|
||||
$this->_idTemplate = array();
|
||||
$this->_resultCounter = 0;
|
||||
$this->_isSimpleQuery = count($this->_rsm->aliasMap) <= 1;
|
||||
|
||||
foreach ($this->_rsm->aliasMap as $dqlAlias => $className) {
|
||||
$this->_identifierMap[$dqlAlias] = array();
|
||||
@ -134,7 +130,8 @@ class ArrayHydrator extends AbstractHydrator
|
||||
}
|
||||
|
||||
$relationAlias = $this->_rsm->relationMap[$dqlAlias];
|
||||
$relation = $this->getClassMetadata($this->_rsm->aliasMap[$parent])->associationMappings[$relationAlias];
|
||||
$parentClass = $this->_metadataCache[$this->_rsm->aliasMap[$parent]];
|
||||
$relation = $parentClass->associationMappings[$relationAlias];
|
||||
|
||||
// Check the type of the relation (many or single-valued)
|
||||
if ( ! ($relation['type'] & ClassMetadata::TO_ONE)) {
|
||||
|
@ -42,22 +42,22 @@ class ObjectHydrator extends AbstractHydrator
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $identifierMap;
|
||||
private $identifierMap = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $resultPointers;
|
||||
private $resultPointers = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $idTemplate;
|
||||
private $idTemplate = array();
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $resultCounter;
|
||||
private $resultCounter = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
@ -79,12 +79,6 @@ class ObjectHydrator extends AbstractHydrator
|
||||
*/
|
||||
protected function prepare()
|
||||
{
|
||||
$this->identifierMap =
|
||||
$this->resultPointers =
|
||||
$this->idTemplate = array();
|
||||
|
||||
$this->resultCounter = 0;
|
||||
|
||||
if ( ! isset($this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD])) {
|
||||
$this->_hints[UnitOfWork::HINT_DEFEREAGERLOAD] = true;
|
||||
}
|
||||
@ -93,25 +87,23 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$this->identifierMap[$dqlAlias] = array();
|
||||
$this->idTemplate[$dqlAlias] = '';
|
||||
|
||||
if ( ! isset($this->ce[$className])) {
|
||||
$this->ce[$className] = $this->_em->getClassMetadata($className);
|
||||
}
|
||||
|
||||
// Remember which associations are "fetch joined", so that we know where to inject
|
||||
// collection stubs or proxies and where not.
|
||||
if ( ! isset($this->_rsm->relationMap[$dqlAlias])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! isset($this->_rsm->aliasMap[$this->_rsm->parentAliasMap[$dqlAlias]])) {
|
||||
throw HydrationException::parentObjectOfRelationNotFound($dqlAlias, $this->_rsm->parentAliasMap[$dqlAlias]);
|
||||
$parent = $this->_rsm->parentAliasMap[$dqlAlias];
|
||||
|
||||
if ( ! isset($this->_rsm->aliasMap[$parent])) {
|
||||
throw HydrationException::parentObjectOfRelationNotFound($dqlAlias, $parent);
|
||||
}
|
||||
|
||||
$sourceClassName = $this->_rsm->aliasMap[$this->_rsm->parentAliasMap[$dqlAlias]];
|
||||
$sourceClassName = $this->_rsm->aliasMap[$parent];
|
||||
$sourceClass = $this->getClassMetadata($sourceClassName);
|
||||
$assoc = $sourceClass->associationMappings[$this->_rsm->relationMap[$dqlAlias]];
|
||||
|
||||
$this->_hints['fetched'][$this->_rsm->parentAliasMap[$dqlAlias]][$assoc['fieldName']] = true;
|
||||
$this->_hints['fetched'][$parent][$assoc['fieldName']] = true;
|
||||
|
||||
if ($assoc['type'] === ClassMetadata::MANY_TO_MANY) {
|
||||
continue;
|
||||
@ -126,7 +118,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
// handle fetch-joined owning side bi-directional one-to-one associations
|
||||
if ($assoc['inversedBy']) {
|
||||
$class = $this->ce[$className];
|
||||
$class = $this->getClassMetadata($className);
|
||||
$inverseAssoc = $class->associationMappings[$assoc['inversedBy']];
|
||||
|
||||
if ( ! ($inverseAssoc['type'] & ClassMetadata::TO_ONE)) {
|
||||
@ -198,7 +190,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
if ( ! $value instanceof PersistentCollection) {
|
||||
$value = new PersistentCollection(
|
||||
$this->_em, $this->ce[$relation['targetEntity']], $value
|
||||
$this->_em, $this->_metadataCache[$relation['targetEntity']], $value
|
||||
);
|
||||
$value->setOwner($entity, $relation);
|
||||
|
||||
@ -255,7 +247,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
throw HydrationException::emptyDiscriminatorValue($dqlAlias);
|
||||
}
|
||||
|
||||
$discrMap = $this->ce[$className]->discriminatorMap;
|
||||
$discrMap = $this->_metadataCache[$className]->discriminatorMap;
|
||||
|
||||
if ( ! isset($discrMap[$data[$discrColumn]])) {
|
||||
throw HydrationException::invalidDiscriminatorValue($data[$discrColumn], array_keys($discrMap));
|
||||
@ -267,7 +259,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
}
|
||||
|
||||
if (isset($this->_hints[Query::HINT_REFRESH_ENTITY]) && isset($this->rootAliases[$dqlAlias])) {
|
||||
$this->registerManaged($this->ce[$className], $this->_hints[Query::HINT_REFRESH_ENTITY], $data);
|
||||
$this->registerManaged($this->_metadataCache[$className], $this->_hints[Query::HINT_REFRESH_ENTITY], $data);
|
||||
}
|
||||
|
||||
$this->_hints['fetchAlias'] = $dqlAlias;
|
||||
@ -284,7 +276,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
private function getEntityFromIdentityMap($className, array $data)
|
||||
{
|
||||
// TODO: Abstract this code and UnitOfWork::createEntity() equivalent?
|
||||
$class = $this->ce[$className];
|
||||
$class = $this->_metadataCache[$className];
|
||||
|
||||
/* @var $class ClassMetadata */
|
||||
if ($class->isIdentifierComposite) {
|
||||
@ -352,7 +344,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
continue;
|
||||
}
|
||||
|
||||
$parentClass = $this->ce[$this->_rsm->aliasMap[$parentAlias]];
|
||||
$parentClass = $this->_metadataCache[$this->_rsm->aliasMap[$parentAlias]];
|
||||
$relationField = $this->_rsm->relationMap[$dqlAlias];
|
||||
$relation = $parentClass->associationMappings[$relationField];
|
||||
$reflField = $parentClass->reflFields[$relationField];
|
||||
@ -439,7 +431,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$element = $this->getEntity($data, $dqlAlias);
|
||||
$reflField->setValue($parentObject, $element);
|
||||
$this->_uow->setOriginalEntityProperty($oid, $relationField, $element);
|
||||
$targetClass = $this->ce[$relation['targetEntity']];
|
||||
$targetClass = $this->_metadataCache[$relation['targetEntity']];
|
||||
|
||||
if ($relation['isOwningSide']) {
|
||||
// TODO: Just check hints['fetched'] here?
|
||||
|
@ -32,9 +32,20 @@ class SimpleObjectHydrator extends AbstractHydrator
|
||||
private $class;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
private $declaringClasses = array();
|
||||
protected function prepare()
|
||||
{
|
||||
if (count($this->_rsm->aliasMap) !== 1) {
|
||||
throw new \RuntimeException("Cannot use SimpleObjectHydrator with a ResultSetMapping that contains more than one object result.");
|
||||
}
|
||||
|
||||
if ($this->_rsm->scalarMappings) {
|
||||
throw new \RuntimeException("Cannot use SimpleObjectHydrator with a ResultSetMapping that contains scalar mappings.");
|
||||
}
|
||||
|
||||
$this->class = $this->getClassMetadata(reset($this->_rsm->aliasMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@ -52,31 +63,6 @@ class SimpleObjectHydrator extends AbstractHydrator
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function prepare()
|
||||
{
|
||||
if (count($this->_rsm->aliasMap) !== 1) {
|
||||
throw new \RuntimeException("Cannot use SimpleObjectHydrator with a ResultSetMapping that contains more than one object result.");
|
||||
}
|
||||
|
||||
if ($this->_rsm->scalarMappings) {
|
||||
throw new \RuntimeException("Cannot use SimpleObjectHydrator with a ResultSetMapping that contains scalar mappings.");
|
||||
}
|
||||
|
||||
$this->class = $this->_em->getClassMetadata(reset($this->_rsm->aliasMap));
|
||||
|
||||
// We only need to add declaring classes if we have inheritance.
|
||||
if ($this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->_rsm->declaringClasses as $column => $class) {
|
||||
$this->declaringClasses[$column] = $this->_em->getClassMetadata($class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user