Skip to content

Commit

Permalink
Merge pull request #558 from lekoala/patch-1
Browse files Browse the repository at this point in the history
Don't make query if not needed
  • Loading branch information
GuySartorelli authored Aug 3, 2023
2 parents 7c8440d + 4bf41f3 commit 1730623
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Shortcodes/FileLinkTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,22 @@ 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);
}
}

// We cannot rely on linkedPages being empty, because we need to remove them if there was any
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 1730623

Please sign in to comment.