From 95fae36b979ce9cdf7831b1378866529ff07afe7 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 18 Sep 2018 13:22:55 +1200 Subject: [PATCH 1/3] 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); From 4369585d740a171666e13a38e48a326b23c98e67 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 21 Sep 2018 18:33:24 +1200 Subject: [PATCH 2/3] FIX: Use Hierarchy::prepopulateTreeDataCache() in CMS. Requires https://github.com/silverstripe/silverstripe-framework/pull/8395 --- code/Controllers/CMSMain.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index fa0ab3a81e..2f0048c131 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -491,13 +491,11 @@ 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); - - if (method_exists(Hierarchy::class, 'prepopulate_numchildren_cache')) { - Hierarchy::prepopulate_numchildren_cache(SiteTree::class, Versioned::DRAFT); - } + $filter = $this->getSearchFilter(); + SiteTree::singleton()->prepopulateTreeDataCache(null, [ + 'childrenMethod' => $filter ? $filter->getChildrenMethod() : 'AllChildrenIncludingDeleted', + 'numChildrenMethod' => $filter ? $filter->getNumChildrenMethod() : 'numChildren', + ]); $html = $this->getSiteTreeFor($this->config()->get('tree_class')); From 32e567dd0b8a70c5320113e88d1ae1a1e95bf8fe Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Tue, 25 Sep 2018 14:54:43 +1200 Subject: [PATCH 3/3] Cache tree_class instead of assuming it will always be SiteTree. --- code/Controllers/CMSMain.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 2f0048c131..a21515d5c6 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -491,13 +491,15 @@ public function LinkPreview() */ public function SiteTreeAsUL() { + $treeClass = $this->config()->get('tree_class'); $filter = $this->getSearchFilter(); - SiteTree::singleton()->prepopulateTreeDataCache(null, [ + + DataObject::singleton($treeClass)->prepopulateTreeDataCache(null, [ 'childrenMethod' => $filter ? $filter->getChildrenMethod() : 'AllChildrenIncludingDeleted', 'numChildrenMethod' => $filter ? $filter->getNumChildrenMethod() : 'numChildren', ]); - $html = $this->getSiteTreeFor($this->config()->get('tree_class')); + $html = $this->getSiteTreeFor($treeClass); $this->extend('updateSiteTreeAsUL', $html);