From 83f6c80e0ed6d1713a6276fb15557d942b919659 Mon Sep 17 00:00:00 2001 From: Nicolaas / Sunn Side Up Date: Wed, 1 Dec 2021 22:31:52 +1300 Subject: [PATCH] MINOR: make use of getParent method to make faster This change will make Silverstripe much faster (i hope), because it uses SiteTree::getParent() instead of the magic / custom method Parent() --- code/Model/SiteTree.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index b8e10c1c1a..ba9e04d2aa 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -642,7 +642,7 @@ public function getMimeType() public function RelativeLink($action = null) { if ($this->ParentID && self::config()->get('nested_urls')) { - $parent = $this->Parent(); + $parent = $this->getParent(); // If page is removed select parent from version history (for archive page view) if ((!$parent || !$parent->exists()) && !$this->isOnDraft()) { $parent = Versioned::get_latest_version(self::class, $this->ParentID); @@ -766,7 +766,7 @@ public function isOrphaned() } // Parent must exist and not be an orphan itself - $parent = $this->Parent(); + $parent = $this->getParent(); return !$parent || !$parent->exists() || $parent->isOrphaned(); } @@ -820,7 +820,7 @@ public function InSection($sectionName) if ($sectionName === $page->URLSegment) { return true; } - $page = $page->Parent(); + $page = $page->getParent(); } return false; } @@ -923,7 +923,7 @@ public function getBreadcrumbItems($maxDepth = 20, $stopAtPageType = false, $sho $pages[] = $page; } - $page = $page->Parent(); + $page = $page->getParent(); } return new ArrayList(array_reverse($pages)); @@ -952,13 +952,13 @@ public function setParent($item) /** * Get the parent of this page. * - * @return SiteTree Parent of this page + * @return SiteTree|null */ public function getParent() { $parentID = $this->getField("ParentID"); if ($parentID) { - return SiteTree::get_by_id(self::class, $parentID); + return SiteTree::get_by_id($parentID); } return null; } @@ -1133,7 +1133,7 @@ public function canView($member = null) // check for inherit if ($this->CanViewType === InheritedPermissions::INHERIT) { if ($this->ParentID) { - return $this->Parent()->canView($member); + return $this->getParent()->canView($member); } else { return $this->getSiteConfig()->canViewPages($member); } @@ -1740,7 +1740,7 @@ public function validURLSegment() // Check known urlsegment blacklists if (self::config()->get('nested_urls') && $this->ParentID) { // Guard against url segments for sub-pages - $parent = $this->Parent(); + $parent = $this->getParent(); if ($controller = ModelAsController::controller_for($parent)) { if ($controller instanceof Controller && $controller->hasAction($this->URLSegment)) { return false; @@ -2001,7 +2001,7 @@ public function getCMSFields() $baseLink = Controller::join_links( Director::absoluteBaseURL(), - (self::config()->get('nested_urls') && $this->ParentID ? $this->Parent()->RelativeLink(true) : null) + (self::config()->get('nested_urls') && $this->ParentID ? $this->getParent()->RelativeLink(true) : null) ); $urlsegment = SiteTreeURLSegmentField::create("URLSegment", $this->fieldLabel('URLSegment')) @@ -2593,7 +2593,7 @@ protected function getClassDropdown() if ($instance instanceof HiddenClass) { continue; } - if (!$instance->canCreate(null, ['Parent' => $this->ParentID ? $this->Parent() : null])) { + if (!$instance->canCreate(null, ['Parent' => $this->ParentID ? $this->getParent() : null])) { continue; } } @@ -2899,7 +2899,7 @@ public function Level($level) { $parent = $this; $stack = [$parent]; - while (($parent = $parent->Parent()) && $parent->exists()) { + while (($parent = $parent->getParent()) && $parent->exists()) { array_unshift($stack, $parent); } @@ -2914,7 +2914,7 @@ public function Level($level) public function getPageLevel() { if ($this->ParentID) { - return 1 + $this->Parent()->getPageLevel(); + return 1 + $this->getParent()->getPageLevel(); } return 1; }