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()
This commit is contained in:
Nicolaas / Sunn Side Up 2021-12-01 22:31:52 +13:00 committed by Guy Sartorelli
parent d5faa0158a
commit e1da194f2c
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A
1 changed files with 12 additions and 12 deletions

View File

@ -684,7 +684,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
public function RelativeLink($action = null) public function RelativeLink($action = null)
{ {
if ($this->ParentID && self::config()->get('nested_urls')) { 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 page is removed select parent from version history (for archive page view)
if ((!$parent || !$parent->exists()) && !$this->isOnDraft()) { if ((!$parent || !$parent->exists()) && !$this->isOnDraft()) {
$parent = Versioned::get_latest_version(self::class, $this->ParentID); $parent = Versioned::get_latest_version(self::class, $this->ParentID);
@ -809,7 +809,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
} }
// Parent must exist and not be an orphan itself // Parent must exist and not be an orphan itself
$parent = $this->Parent(); $parent = $this->getParent();
return !$parent || !$parent->exists() || $parent->isOrphaned(); return !$parent || !$parent->exists() || $parent->isOrphaned();
} }
@ -863,7 +863,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
if ($sectionName === $page->URLSegment) { if ($sectionName === $page->URLSegment) {
return true; return true;
} }
$page = $page->Parent(); $page = $page->getParent();
} }
return false; return false;
} }
@ -966,7 +966,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$pages[] = $page; $pages[] = $page;
} }
$page = $page->Parent(); $page = $page->getParent();
} }
return new ArrayList(array_reverse($pages ?? [])); return new ArrayList(array_reverse($pages ?? []));
@ -995,13 +995,13 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
/** /**
* Get the parent of this page. * Get the parent of this page.
* *
* @return SiteTree Parent of this page * @return SiteTree|null
*/ */
public function getParent() public function getParent()
{ {
$parentID = $this->getField("ParentID"); $parentID = $this->getField("ParentID");
if ($parentID) { if ($parentID) {
return SiteTree::get_by_id(self::class, $parentID); return SiteTree::get_by_id($parentID);
} }
return null; return null;
} }
@ -1176,7 +1176,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// check for inherit // check for inherit
if ($this->CanViewType === InheritedPermissions::INHERIT) { if ($this->CanViewType === InheritedPermissions::INHERIT) {
if ($this->ParentID) { if ($this->ParentID) {
return $this->Parent()->canView($member); return $this->getParent()->canView($member);
} else { } else {
return $this->getSiteConfig()->canViewPages($member); return $this->getSiteConfig()->canViewPages($member);
} }
@ -1872,7 +1872,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// Check known urlsegment blacklists // Check known urlsegment blacklists
if (self::config()->get('nested_urls') && $this->ParentID) { if (self::config()->get('nested_urls') && $this->ParentID) {
// Guard against url segments for sub-pages // Guard against url segments for sub-pages
$parent = $this->Parent(); $parent = $this->getParent();
if ($controller = ModelAsController::controller_for($parent)) { if ($controller = ModelAsController::controller_for($parent)) {
if ($controller instanceof Controller && $controller->hasAction($this->URLSegment)) { if ($controller instanceof Controller && $controller->hasAction($this->URLSegment)) {
return false; return false;
@ -2132,7 +2132,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$baseLink = Controller::join_links( $baseLink = Controller::join_links(
Director::absoluteBaseURL(), 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')) $urlsegment = SiteTreeURLSegmentField::create("URLSegment", $this->fieldLabel('URLSegment'))
@ -2755,7 +2755,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
if ($instance instanceof HiddenClass) { if ($instance instanceof HiddenClass) {
continue; continue;
} }
if (!$instance->canCreate(null, ['Parent' => $this->ParentID ? $this->Parent() : null])) { if (!$instance->canCreate(null, ['Parent' => $this->ParentID ? $this->getParent() : null])) {
continue; continue;
} }
} }
@ -3033,7 +3033,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{ {
$parent = $this; $parent = $this;
$stack = [$parent]; $stack = [$parent];
while (($parent = $parent->Parent()) && $parent->exists()) { while (($parent = $parent->getParent()) && $parent->exists()) {
array_unshift($stack, $parent); array_unshift($stack, $parent);
} }
@ -3048,7 +3048,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
public function getPageLevel() public function getPageLevel()
{ {
if ($this->ParentID) { if ($this->ParentID) {
return 1 + $this->Parent()->getPageLevel(); return 1 + $this->getParent()->getPageLevel();
} }
return 1; return 1;
} }