Skip to content

Commit

Permalink
FIX: Use Hierarchy::prepopulateTreeDataCache() in CMS (#2266)
Browse files Browse the repository at this point in the history
* FIX: Use Hierarchy::prepopulate_numchildren_cache in tree-generation

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

See silverstripe/silverstripe-framework#8379

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

Requires silverstripe/silverstripe-framework#8395

* Cache tree_class instead of assuming it will always be SiteTree.
  • Loading branch information
Sam Minnée authored and maxime-rainville committed Sep 25, 2018
1 parent 6e7bc38 commit 5bfc37f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\HiddenClass;
use SilverStripe\ORM\Hierarchy\Hierarchy;
use SilverStripe\ORM\Hierarchy\MarkedSet;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\ValidationResult;
Expand Down Expand Up @@ -490,10 +491,15 @@ public function LinkPreview()
*/
public function SiteTreeAsUL()
{
// Pre-cache sitetree version numbers for querying efficiency
Versioned::prepopulate_versionnumber_cache(SiteTree::class, Versioned::DRAFT);
Versioned::prepopulate_versionnumber_cache(SiteTree::class, Versioned::LIVE);
$html = $this->getSiteTreeFor($this->config()->get('tree_class'));
$treeClass = $this->config()->get('tree_class');
$filter = $this->getSearchFilter();

DataObject::singleton($treeClass)->prepopulateTreeDataCache(null, [
'childrenMethod' => $filter ? $filter->getChildrenMethod() : 'AllChildrenIncludingDeleted',
'numChildrenMethod' => $filter ? $filter->getNumChildrenMethod() : 'numChildren',
]);

$html = $this->getSiteTreeFor($treeClass);

$this->extend('updateSiteTreeAsUL', $html);

Expand Down

0 comments on commit 5bfc37f

Please sign in to comment.