From 5bfc37ff4bd22e8bbc02dc4f6dae59d25a4d5e67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sam=20Minn=C3=A9e?= Date: Tue, 25 Sep 2018 15:14:16 +1200 Subject: [PATCH] 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. --- code/Controllers/CMSMain.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index dbd48d5b21..a21515d5c6 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -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; @@ -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);