Merge pull request #2330 from open-sausages/pulls/4.3/speed-boost-for-dependent-pages

MINOR Speed up DependentPages by shifting existence check to table join
This commit is contained in:
Maxime Rainville 2018-11-16 16:08:34 +13:00 committed by GitHub
commit ab4c156948
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1727,19 +1727,41 @@ 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 $siteTreelinkTable = SiteTreeLink::singleton()->baseTable();
$item = $link->Parent();
if ($item && $item->isInDB()) { // Get the list of back links classes
$list->push($item); $parentClasses = $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 ($parentClasses as $parentClass) {
$joinClause = sprintf(
"\"%s\".\"ParentID\"=\"%s\".\"ID\"",
$siteTreelinkTable,
DataObject::singleton($parentClass)->baseTable()
);
$links = DataObject::get($parentClass)
->innerJoin(
$siteTreelinkTable,
$joinClause
)
->where([
"\"$siteTreelinkTable\".\"LinkedID\"" => $this->ID,
"\"$siteTreelinkTable\".\"ParentClass\"" => $parentClass,
])
->alterDataQuery(function ($query) {
$query->selectField("'Content link'", "DependentLinkType");
});
$list->merge($links);
} }
return $list; return $list;
} }
@ -1761,40 +1783,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);