BUGFIX: Remove cache for Hierarchy::AllChildren() and Hierarchy::AllChildrenIncludingDeleted(), since they increase memory usage unnecessarily. (from r100980)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@111555 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-04 04:28:32 +00:00
parent dd44a010cf
commit 32038ab3ce

View File

@ -386,18 +386,6 @@ class Hierarchy extends DataObjectDecorator {
} }
} }
/**
* Cached result for AllChildren().
* @var DataObjectSet
*/
protected $_cache_allChildren;
/**
* Cached result for AllChildrenIncludingDeleted().
* @var DataObjectSet
*/
protected $_cache_allChildrenIncludingDeleted;
/** /**
* Get the children for this DataObject. * Get the children for this DataObject.
* @return DataObjectSet * @return DataObjectSet
@ -422,13 +410,7 @@ class Hierarchy extends DataObjectDecorator {
* @return DataObjectSet * @return DataObjectSet
*/ */
public function AllChildren() { public function AllChildren() {
// Cache the allChildren data, so that future requests will return the references to the same return $this->owner->stageChildren(true);
// object. This allows the mark..() system to work appropriately.
if(!$this->_cache_allChildren) {
$this->_cache_allChildren = $this->owner->stageChildren(true);
}
return $this->_cache_allChildren;
} }
/** /**
@ -455,33 +437,28 @@ class Hierarchy extends DataObjectDecorator {
$idxStageChildren = array(); $idxStageChildren = array();
$idxLiveChildren = array(); $idxLiveChildren = array();
// Cache the allChildren data, so that future requests will return the references to the same $baseClass = ClassInfo::baseDataClass($this->owner->class);
// object. This allows the mark..() system to work appropriately. if($baseClass) {
if(!$this->_cache_allChildrenIncludingDeleted) { $stageChildren = $this->owner->stageChildren(true);
$baseClass = ClassInfo::baseDataClass($this->owner->class);
if($baseClass) { // Add live site content that doesn't exist on the stage site, if required.
$stageChildren = $this->owner->stageChildren(true); if($this->owner->hasExtension('Versioned')) {
$this->_cache_allChildrenIncludingDeleted = $stageChildren; // Next, go through the live children. Only some of these will be listed
$liveChildren = $this->owner->liveChildren(true, true);
// Add live site content that doesn't exist on the stage site, if required. if($liveChildren) {
if($this->owner->hasExtension('Versioned')) { foreach($liveChildren as $child) {
// Next, go through the live children. Only some of these will be listed $stageChildren->push($child);
$liveChildren = $this->owner->liveChildren(true, true);
if($liveChildren) {
foreach($liveChildren as $child) {
$this->_cache_allChildrenIncludingDeleted->push($child);
}
} }
} }
$this->owner->extend("augmentAllChildrenIncludingDeleted", $stageChildren, $context);
} else {
user_error("Hierarchy::AllChildren() Couldn't determine base class for '{$this->owner->class}'", E_USER_ERROR);
} }
$this->owner->extend("augmentAllChildrenIncludingDeleted", $stageChildren, $context);
} else {
user_error("Hierarchy::AllChildren() Couldn't determine base class for '{$this->owner->class}'", E_USER_ERROR);
} }
return $this->_cache_allChildrenIncludingDeleted; return $stageChildren;
} }
/** /**
@ -651,14 +628,7 @@ class Hierarchy extends DataObjectDecorator {
$nextNode = null; $nextNode = null;
$baseClass = ClassInfo::baseDataClass($this->owner->class); $baseClass = ClassInfo::baseDataClass($this->owner->class);
// Try searching for the next node of the given class in each of the children, but treat each $children = DataObject::get(ClassInfo::baseDataClass($this->owner->class), "\"$baseClass\".\"ParentID\"={$this->owner->ID}" . ( ( $afterNode ) ? " AND \"Sort\" > " . sprintf( '%d', $afterNode->Sort ) : "" ), '"Sort" ASC');
// child as the root of the search. This will stop the recursive call from searching backwards.
// If afterNode is given, then only search for the nodes after
if(!$afterNode || $afterNode->ParentID != $this->owner->ID) {
$children = $this->_cache_allChildren;
} else {
$children = DataObject::get(ClassInfo::baseDataClass($this->owner->class), "\"$baseClass\".\"ParentID\"={$this->owner->ID}" . ( ( $afterNode ) ? " AND \"Sort\" > " . sprintf( '%d', $afterNode->Sort ) : "" ), '"Sort" ASC');
}
// Try all the siblings of this node after the given node // Try all the siblings of this node after the given node
/*if( $siblings = DataObject::get( ClassInfo::baseDataClass($this->owner->class), "\"ParentID\"={$this->owner->ParentID}" . ( $afterNode ) ? "\"Sort\" > {$afterNode->Sort}" : "" , '\"Sort\" ASC' ) ) /*if( $siblings = DataObject::get( ClassInfo::baseDataClass($this->owner->class), "\"ParentID\"={$this->owner->ParentID}" . ( $afterNode ) ? "\"Sort\" > {$afterNode->Sort}" : "" , '\"Sort\" ASC' ) )
@ -686,8 +656,6 @@ class Hierarchy extends DataObjectDecorator {
function flushCache() { function flushCache() {
$this->_cache_children = null; $this->_cache_children = null;
$this->_cache_allChildrenIncludingDeleted = null;
$this->_cache_allChildren = null;
$this->_cache_numChildren = null; $this->_cache_numChildren = null;
} }