Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MINOR Added caching to SiteTree->getStatusFlags(), as its called twic…

…e for every node now in LeftAndMain->SiteTreeAsUL() (see #7410)
  • Loading branch information...
commit e50936fe9f128b355754edc03f1dd13ecad4ec19 1 parent bc2fb3c
@chillu chillu authored
Showing with 40 additions and 28 deletions.
  1. +38 −26 code/model/SiteTree.php
  2. +2 −2 tests/model/SiteTreeTest.php
View
64 code/model/SiteTree.php
@@ -195,11 +195,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* See {@link batch_permission_check()} for details.
*/
public static $cache_permissions = array();
-
+
/**
* @var boolean
*/
protected static $enforce_strict_hierarchy = true;
+
+ protected $_cache_statusFlags = null;
/**
* Determines if the system should avoid orphaned pages
@@ -1493,6 +1495,11 @@ function onAfterDelete() {
parent::onAfterDelete();
}
+
+ function flushCache($persistent = true) {
+ parent::flushCache($persistent);
+ $this->_cache_statusFlags = null;
+ }
function validate() {
$result = parent::validate();
@@ -2469,38 +2476,43 @@ function setMenuTitle($value) {
*
* Example (with optional title attribute):
* "deletedonlive" => array('text' => "Deleted", 'title' => 'This page has been deleted')
- *
+ *
+ * @param Boolean $cached
* @return array
*/
- function getStatusFlags() {
- $flags = array();
- if($this->IsDeletedFromStage) {
- if($this->ExistsOnLive) {
- $flags['removedfromdraft'] = array(
- 'text' => _t('SiteTree.REMOVEDFROMDRAFTSHORT', 'Removed from draft'),
- 'title' => _t('SiteTree.REMOVEDFROMDRAFTHELP', 'Page is published, but has been deleted from draft'),
+ function getStatusFlags($cached = true) {
+ if(!$this->_cache_statusFlags || !$cached) {
+ $flags = array();
+ if($this->IsDeletedFromStage) {
+ if($this->ExistsOnLive) {
+ $flags['removedfromdraft'] = array(
+ 'text' => _t('SiteTree.REMOVEDFROMDRAFTSHORT', 'Removed from draft'),
+ 'title' => _t('SiteTree.REMOVEDFROMDRAFTHELP', 'Page is published, but has been deleted from draft'),
+ );
+ } else {
+ $flags['deletedonlive'] = array(
+ 'text' => _t('SiteTree.DELETEDPAGESHORT', 'Deleted'),
+ 'title' => _t('SiteTree.DELETEDPAGEHELP', 'Page is no longer published'),
+ );
+ }
+ } else if($this->IsAddedToStage) {
+ $flags['addedtodraft'] = array(
+ 'text' => _t('SiteTree.ADDEDTODRAFTSHORT', 'Draft'),
+ 'title' => _t('SiteTree.ADDEDTODRAFTHELP', "Page has not been published yet")
);
- } else {
- $flags['deletedonlive'] = array(
- 'text' => _t('SiteTree.DELETEDPAGESHORT', 'Deleted'),
- 'title' => _t('SiteTree.DELETEDPAGEHELP', 'Page is no longer published'),
+ } else if($this->IsModifiedOnStage) {
+ $flags['modified'] = array(
+ 'text' => _t('SiteTree.MODIFIEDONDRAFTSHORT', 'Modified'),
+ 'title' => _t('SiteTree.MODIFIEDONDRAFTHELP', 'Page has unpublished changes'),
);
}
- } else if($this->IsAddedToStage) {
- $flags['addedtodraft'] = array(
- 'text' => _t('SiteTree.ADDEDTODRAFTSHORT', 'Draft'),
- 'title' => _t('SiteTree.ADDEDTODRAFTHELP', "Page has not been published yet")
- );
- } else if($this->IsModifiedOnStage) {
- $flags['modified'] = array(
- 'text' => _t('SiteTree.MODIFIEDONDRAFTSHORT', 'Modified'),
- 'title' => _t('SiteTree.MODIFIEDONDRAFTHELP', 'Page has unpublished changes'),
- );
- }
- $this->extend('updateStatusFlags', $flags);
+ $this->extend('updateStatusFlags', $flags);
+
+ $this->_cache_statusFlags = $flags;
+ }
- return $flags;
+ return $this->_cache_statusFlags;
}
View
4 tests/model/SiteTreeTest.php
@@ -956,8 +956,8 @@ class SiteTreeTest_NotRoot extends Page implements TestOnly {
}
class SiteTreeTest_StageStatusInherit extends SiteTree implements TestOnly {
- function getStatusFlags(){
- $flags = parent::getStatusFlags();
+ function getStatusFlags($cached = true){
+ $flags = parent::getStatusFlags($cached);
$flags['inherited-class'] = "InheritedTitle";
return $flags;
}
Please sign in to comment.
Something went wrong with that request. Please try again.