From d085d6ddc8f5d11bd5f3de596ed91ccf49dca062 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 18 Sep 2018 13:22:55 +1200 Subject: [PATCH] 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 --- code/Controllers/CMSMain.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index dbd48d5b21..fa0ab3a81e 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; @@ -493,6 +494,11 @@ 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); + + if (method_exists(Hierarchy::class, 'prepopulate_numchildren_cache')) { + Hierarchy::prepopulate_numchildren_cache(SiteTree::class, Versioned::DRAFT); + } + $html = $this->getSiteTreeFor($this->config()->get('tree_class')); $this->extend('updateSiteTreeAsUL', $html);