Skip to content

Commit

Permalink
Don't make query if not needed
Browse files Browse the repository at this point in the history
setByIDList will make a query even though there are no DBHTMLText for this DataObject

Checking the presence of these fields allow to return early and prevent the needless query
  • Loading branch information
lekoala committed Jun 22, 2023
1 parent 7db8cde commit a7d5386
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Shortcodes/FileLinkTracking.php
Expand Up @@ -131,15 +131,21 @@ public function augmentSyncLinkTracking()
$allFields = DataObject::getSchema()->fieldSpecs($this->owner);
$linkedPages = [];
$anyBroken = false;
$hasTrackedFields = false;
foreach ($allFields as $field => $fieldSpec) {
$fieldObj = $this->owner->dbObject($field);
if ($fieldObj instanceof DBHTMLText) {
$hasTrackedFields = true;
// Merge links in this field with global list.
$linksInField = $this->trackLinksInField($field, $anyBroken);
$linkedPages = array_merge($linkedPages, $linksInField);
}
}

if (!$hasTrackedFields) {
return;
}

// Soft support for HasBrokenFile db field (e.g. SiteTree)
if ($this->owner->hasField('HasBrokenFile')) {
$this->owner->HasBrokenFile = $anyBroken;
Expand Down

0 comments on commit a7d5386

Please sign in to comment.