From a7d538688032f74cbada50f2bce0fc044a359901 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Thu, 22 Jun 2023 10:46:30 +0200 Subject: [PATCH 1/2] Don't make query if not needed 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 --- src/Shortcodes/FileLinkTracking.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Shortcodes/FileLinkTracking.php b/src/Shortcodes/FileLinkTracking.php index 5eaa79a7..048d824d 100644 --- a/src/Shortcodes/FileLinkTracking.php +++ b/src/Shortcodes/FileLinkTracking.php @@ -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; From 4bf41f3d2420784afde0a732e4c5c341254196c4 Mon Sep 17 00:00:00 2001 From: Thomas Portelange Date: Thu, 3 Aug 2023 09:09:43 +0200 Subject: [PATCH 2/2] Update FileLinkTracking.php --- src/Shortcodes/FileLinkTracking.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Shortcodes/FileLinkTracking.php b/src/Shortcodes/FileLinkTracking.php index 048d824d..a182f5c0 100644 --- a/src/Shortcodes/FileLinkTracking.php +++ b/src/Shortcodes/FileLinkTracking.php @@ -142,6 +142,7 @@ public function augmentSyncLinkTracking() } } + // We cannot rely on linkedPages being empty, because we need to remove them if there was any if (!$hasTrackedFields) { return; }