MINOR Speed up DependentPages by shifting existence check to table join

This commit is contained in:
Maxime Rainville 2018-11-14 18:01:29 +13:00
parent 40c421b8db
commit 0bff8728b1

View File

@ -1727,19 +1727,37 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
/** /**
* Get the back-link tracking objects that link to this page * Get the back-link tracking objects that link to this page
* *
* @retun ArrayList|DataObject[] * @return ArrayList|DataObject[]
*/ */
public function BackLinkTracking() public function BackLinkTracking()
{ {
// @todo - Implement PolymorphicManyManyList to replace this // @todo - Implement PolymorphicManyManyList to replace this
$list = ArrayList::create(); $list = ArrayList::create();
foreach ($this->BackLinks() as $link) {
// Ensure parent record exists $joinClause = sprintf(
$item = $link->Parent(); "\"%s\".\"ParentID\"=\"ParentRelationTable\".\"ID\"",
if ($item && $item->isInDB()) { SiteTreeLink::singleton()->baseTable()
$list->push($item); );
}
// Get the list of back links classes
$linkClasses = $this->BackLinks()->exclude(['ParentClass' => null])->columnUnique('ParentClass');
// Get list of sitreTreelink and join them to the their parent class to make sure we don't get orphan records.
foreach ($linkClasses as $linkClass) {
$links = $this->BackLinks()
->filter(['ParentClass' => $linkClass])
->innerJoin(
DataObject::singleton($linkClass)->baseTable(),
$joinClause,
'ParentRelationTable'
)
->alterDataQuery(function ($query) {
$query->selectField("'Content link'", "DependentLinkType");
})
;
$list->merge($links);
} }
return $list; return $list;
} }
@ -1761,40 +1779,26 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
// We merge all into a regular SS_List, because DataList doesn't support merge // We merge all into a regular SS_List, because DataList doesn't support merge
if ($contentLinks = $this->BackLinkTracking()) { if ($contentLinks = $this->BackLinkTracking()) {
$linkList = new ArrayList(); $items->merge($contentLinks);
foreach ($contentLinks as $item) {
$item->DependentLinkType = 'Content link';
$linkList->push($item);
}
$items->merge($linkList);
} }
// Virtual pages // Virtual pages
if ($includeVirtuals) { if ($includeVirtuals) {
$virtuals = $this->VirtualPages(); $virtuals = $this->VirtualPages()
if ($virtuals) { ->alterDataQuery(function ($query) {
$virtualList = new ArrayList(); $query->selectField("'Virtual page'", "DependentLinkType");
foreach ($virtuals as $item) { });
$item->DependentLinkType = 'Virtual page'; $items->merge($virtuals);
$virtualList->push($item);
}
$items->merge($virtualList);
}
} }
// Redirector pages // Redirector pages
$redirectors = RedirectorPage::get()->where(array( $redirectors = RedirectorPage::get()->where(array(
'"RedirectorPage"."RedirectionType"' => 'Internal', '"RedirectorPage"."RedirectionType"' => 'Internal',
'"RedirectorPage"."LinkToID"' => $this->ID '"RedirectorPage"."LinkToID"' => $this->ID
)); ))->alterDataQuery(function ($query) {
if ($redirectors) { $query->selectField("'Redirector page'", "DependentLinkType");
$redirectorList = new ArrayList(); });
foreach ($redirectors as $item) { $items->merge($redirectors);
$item->DependentLinkType = 'Redirector page';
$redirectorList->push($item);
}
$items->merge($redirectorList);
}
if (class_exists('Subsite')) { if (class_exists('Subsite')) {
Subsite::disable_subsite_filter($origDisableSubsiteFilter); Subsite::disable_subsite_filter($origDisableSubsiteFilter);