Improving metadata caching performance by only serializing what is absolutely necessary.
This commit is contained in:
parent
4b39705cd4
commit
4b71afe7c2
@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
@ -341,4 +341,57 @@ abstract class AssociationMapping
|
|||||||
: $this->joinTable['name'];
|
: $this->joinTable['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines which fields get serialized.
|
||||||
|
*
|
||||||
|
* It is only serialized what is necessary for best unserialization performance.
|
||||||
|
* That means any metadata properties that are not set or empty or simply have
|
||||||
|
* their default value are NOT serialized.
|
||||||
|
*
|
||||||
|
* @return array The names of all the fields that should be serialized.
|
||||||
|
*/
|
||||||
|
public function __sleep()
|
||||||
|
{
|
||||||
|
$serialized = array(
|
||||||
|
'sourceEntityName',
|
||||||
|
'targetEntityName',
|
||||||
|
'sourceFieldName'
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->isCascadeDetach) {
|
||||||
|
$serialized[] = 'isCascadeDetach';
|
||||||
|
}
|
||||||
|
if ($this->isCascadeMerge) {
|
||||||
|
$serialized[] = 'isCascadeMerge';
|
||||||
|
}
|
||||||
|
if ($this->isCascadePersist) {
|
||||||
|
$serialized[] = 'isCascadePersist';
|
||||||
|
}
|
||||||
|
if ($this->isCascadeRefresh) {
|
||||||
|
$serialized[] = 'isCascadeRefresh';
|
||||||
|
}
|
||||||
|
if ($this->isCascadeRemove) {
|
||||||
|
$serialized[] = 'isCascadeRemove';
|
||||||
|
}
|
||||||
|
if ( ! $this->isOwningSide) {
|
||||||
|
$serialized[] = 'isOwningSide';
|
||||||
|
}
|
||||||
|
if ($this->mappedBy) {
|
||||||
|
$serialized[] = 'mappedBy';
|
||||||
|
}
|
||||||
|
if ($this->inversedBy) {
|
||||||
|
$serialized[] = 'inversedBy';
|
||||||
|
}
|
||||||
|
if ($this->joinTable) {
|
||||||
|
$serialized[] = 'joinTable';
|
||||||
|
}
|
||||||
|
if ($this->inherited) {
|
||||||
|
$serialized[] = 'inherited';
|
||||||
|
}
|
||||||
|
if ($this->declared) {
|
||||||
|
$serialized[] = 'declared';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $serialized;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,11 @@ class ClassMetadata extends ClassMetadataInfo
|
|||||||
/**
|
/**
|
||||||
* Determines which fields get serialized.
|
* Determines which fields get serialized.
|
||||||
*
|
*
|
||||||
* Parts that are NOT serialized because they can not be properly unserialized:
|
* It is only serialized what is necessary for best unserialization performance.
|
||||||
|
* That means any metadata properties that are not set or empty or simply have
|
||||||
|
* their default value are NOT serialized.
|
||||||
|
*
|
||||||
|
* Parts that are also NOT serialized because they can not be properly unserialized:
|
||||||
* - reflClass (ReflectionClass)
|
* - reflClass (ReflectionClass)
|
||||||
* - reflFields (ReflectionProperty array)
|
* - reflFields (ReflectionProperty array)
|
||||||
*
|
*
|
||||||
@ -273,31 +277,56 @@ class ClassMetadata extends ClassMetadataInfo
|
|||||||
*/
|
*/
|
||||||
public function __sleep()
|
public function __sleep()
|
||||||
{
|
{
|
||||||
return array(
|
// This metadata is always serialized/cached.
|
||||||
'associationMappings', // unserialization "bottleneck" with many associations
|
$serialized = array(
|
||||||
'changeTrackingPolicy',
|
'associationMappings',
|
||||||
'columnNames', //TODO: Not really needed. Can use fieldMappings[$fieldName]['columnName']
|
'columnNames', //TODO: Not really needed. Can use fieldMappings[$fieldName]['columnName']
|
||||||
'customRepositoryClassName',
|
'fieldMappings',
|
||||||
'discriminatorColumn',
|
|
||||||
'discriminatorValue',
|
|
||||||
'discriminatorMap',
|
|
||||||
'fieldMappings',//TODO: Not all of this stuff needs to be serialized. Only type, columnName and fieldName.
|
|
||||||
'fieldNames',
|
'fieldNames',
|
||||||
'generatorType',
|
|
||||||
'identifier',
|
'identifier',
|
||||||
'idGenerator', //TODO: Does not really need to be serialized. Could be moved to runtime.
|
'isIdentifierComposite', // TODO: REMOVE
|
||||||
'inheritanceType',
|
|
||||||
'isIdentifierComposite',
|
|
||||||
'isMappedSuperclass',
|
|
||||||
'isVersioned',
|
|
||||||
'lifecycleCallbacks',
|
|
||||||
'name',
|
'name',
|
||||||
'parentClasses',
|
|
||||||
'table',
|
'table',
|
||||||
'rootEntityName',
|
'rootEntityName',
|
||||||
'subClasses',
|
'idGenerator', //TODO: Does not really need to be serialized. Could be moved to runtime.
|
||||||
'versionField'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// The rest of the metadata is only serialized if necessary.
|
||||||
|
if ($this->changeTrackingPolicy != self::CHANGETRACKING_DEFERRED_IMPLICIT) {
|
||||||
|
$serialized[] = 'changeTrackingPolicy';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->customRepositoryClassName) {
|
||||||
|
$serialized[] = 'customRepositoryClassName';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->inheritanceType != self::INHERITANCE_TYPE_NONE) {
|
||||||
|
$serialized[] = 'inheritanceType';
|
||||||
|
$serialized[] = 'discriminatorColumn';
|
||||||
|
$serialized[] = 'discriminatorValue';
|
||||||
|
$serialized[] = 'discriminatorMap';
|
||||||
|
$serialized[] = 'parentClasses';
|
||||||
|
$serialized[] = 'subClasses';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->generatorType != self::GENERATOR_TYPE_NONE) {
|
||||||
|
$serialized[] = 'generatorType';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isMappedSuperclass) {
|
||||||
|
$serialized[] = 'isMappedSuperclass';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->isVersioned) {
|
||||||
|
$serialized[] = 'isVersioned';
|
||||||
|
$serialized[] = 'versionField';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->lifecycleCallbacks) {
|
||||||
|
$serialized[] = 'lifecycleCallbacks';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
@ -182,4 +180,25 @@ class ManyToManyMapping extends AssociationMapping
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines which fields get serialized.
|
||||||
|
*
|
||||||
|
* It is only serialized what is necessary for best unserialization performance.
|
||||||
|
* That means any metadata properties that are not set or empty or simply have
|
||||||
|
* their default value are NOT serialized.
|
||||||
|
*
|
||||||
|
* @return array The names of all the fields that should be serialized.
|
||||||
|
*/
|
||||||
|
public function __sleep()
|
||||||
|
{
|
||||||
|
$serialized = parent::__sleep();
|
||||||
|
$serialized[] = 'joinTableColumns';
|
||||||
|
$serialized[] = 'relationToSourceKeyColumns';
|
||||||
|
$serialized[] = 'relationToTargetKeyColumns';
|
||||||
|
if ($this->orderBy) {
|
||||||
|
$serialized[] = 'orderBy';
|
||||||
|
}
|
||||||
|
return $serialized;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
@ -136,4 +134,25 @@ class OneToManyMapping extends AssociationMapping
|
|||||||
|
|
||||||
$persister->loadOneToManyCollection($this, $conditions, $targetCollection);
|
$persister->loadOneToManyCollection($this, $conditions, $targetCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines which fields get serialized.
|
||||||
|
*
|
||||||
|
* It is only serialized what is necessary for best unserialization performance.
|
||||||
|
* That means any metadata properties that are not set or empty or simply have
|
||||||
|
* their default value are NOT serialized.
|
||||||
|
*
|
||||||
|
* @return array The names of all the fields that should be serialized.
|
||||||
|
*/
|
||||||
|
public function __sleep()
|
||||||
|
{
|
||||||
|
$serialized = parent::__sleep();
|
||||||
|
if ($this->orderBy) {
|
||||||
|
$serialized[] = 'orderBy';
|
||||||
|
}
|
||||||
|
if ($this->orphanRemoval) {
|
||||||
|
$serialized[] = 'orphanRemoval';
|
||||||
|
}
|
||||||
|
return $serialized;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
@ -187,4 +185,26 @@ class OneToOneMapping extends AssociationMapping
|
|||||||
|
|
||||||
return $targetEntity;
|
return $targetEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines which fields get serialized.
|
||||||
|
*
|
||||||
|
* It is only serialized what is necessary for best unserialization performance.
|
||||||
|
* That means any metadata properties that are not set or empty or simply have
|
||||||
|
* their default value are NOT serialized.
|
||||||
|
*
|
||||||
|
* @return array The names of all the fields that should be serialized.
|
||||||
|
*/
|
||||||
|
public function __sleep()
|
||||||
|
{
|
||||||
|
$serialized = parent::__sleep();
|
||||||
|
$serialized[] = 'joinColumns';
|
||||||
|
$serialized[] = 'joinColumnFieldNames';
|
||||||
|
$serialized[] = 'sourceToTargetKeyColumns';
|
||||||
|
$serialized[] = 'targetToSourceKeyColumns';
|
||||||
|
if ($this->orphanRemoval) {
|
||||||
|
$serialized[] = 'orphanRemoval';
|
||||||
|
}
|
||||||
|
return $serialized;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,10 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->rootEntityName);
|
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsUser', $cm->rootEntityName);
|
||||||
$this->assertEquals(array(), $cm->subClasses);
|
$this->assertEquals(array(), $cm->subClasses);
|
||||||
$this->assertEquals(array(), $cm->parentClasses);
|
$this->assertEquals(array(), $cm->parentClasses);
|
||||||
|
$this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm->inheritanceType);
|
||||||
|
|
||||||
// Customize state
|
// Customize state
|
||||||
|
$cm->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE);
|
||||||
$cm->setSubclasses(array("One", "Two", "Three"));
|
$cm->setSubclasses(array("One", "Two", "Three"));
|
||||||
$cm->setParentClasses(array("UserParent"));
|
$cm->setParentClasses(array("UserParent"));
|
||||||
$cm->setCustomRepositoryClass("UserRepository");
|
$cm->setCustomRepositoryClass("UserRepository");
|
||||||
|
Loading…
Reference in New Issue
Block a user