Skip to content

Commit

Permalink
Don't make query if not needed (#2863)
Browse files Browse the repository at this point in the history
* Don't make query if not needed

See silverstripe/silverstripe-assets#557 for background

* add comment
  • Loading branch information
lekoala committed Aug 18, 2023
1 parent 7a17383 commit 3295dd5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions code/Model/SiteTreeLinkTracking.php
Expand Up @@ -116,15 +116,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 need a boolean flag instead of checking linkedPages because it can be empty when pages are removed
if (!$hasTrackedFields) {
return;
}

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

0 comments on commit 3295dd5

Please sign in to comment.