FIX: Use Hierarchy::prepopulateTreeDataCache() in CMS (#2266)

* FIX: Use Hierarchy::prepopulate_numchildren_cache in tree-generation

Only relevant if https://github.com/silverstripe/silverstripe-framework/pull/8380 is avialable,
however coded defensively so it can be merged before that PR if needs 
be.

See https://github.com/silverstripe/silverstripe-framework/issues/8379

* FIX: Use Hierarchy::prepopulateTreeDataCache() in CMS.

Requires https://github.com/silverstripe/silverstripe-framework/pull/8395

* Cache tree_class instead of assuming it will always be SiteTree.
This commit is contained in:
Sam Minnée 2018-09-25 15:14:16 +12:00 committed by Maxime Rainville
parent 6e7bc38aad
commit 5bfc37ff4b

View File

@ -54,6 +54,7 @@ use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\HiddenClass; use SilverStripe\ORM\HiddenClass;
use SilverStripe\ORM\Hierarchy\Hierarchy;
use SilverStripe\ORM\Hierarchy\MarkedSet; use SilverStripe\ORM\Hierarchy\MarkedSet;
use SilverStripe\ORM\SS_List; use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\ValidationResult; use SilverStripe\ORM\ValidationResult;
@ -490,10 +491,15 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
*/ */
public function SiteTreeAsUL() public function SiteTreeAsUL()
{ {
// Pre-cache sitetree version numbers for querying efficiency $treeClass = $this->config()->get('tree_class');
Versioned::prepopulate_versionnumber_cache(SiteTree::class, Versioned::DRAFT); $filter = $this->getSearchFilter();
Versioned::prepopulate_versionnumber_cache(SiteTree::class, Versioned::LIVE);
$html = $this->getSiteTreeFor($this->config()->get('tree_class')); DataObject::singleton($treeClass)->prepopulateTreeDataCache(null, [
'childrenMethod' => $filter ? $filter->getChildrenMethod() : 'AllChildrenIncludingDeleted',
'numChildrenMethod' => $filter ? $filter->getNumChildrenMethod() : 'numChildren',
]);
$html = $this->getSiteTreeFor($treeClass);
$this->extend('updateSiteTreeAsUL', $html); $this->extend('updateSiteTreeAsUL', $html);