Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileLinkTracking::augmentSyncLinkTracking should not make make queries if there are no tracked fields #557

Closed
lekoala opened this issue Jun 22, 2023 · 2 comments

Comments

@lekoala
Copy link
Contributor

lekoala commented Jun 22, 2023

Recently found this by chance

It seems that since FileLinkTracking is attached to the dataobject, it runs for classes that are not relevant (eg: LoginSession)

image

By checking if there are actually any DBHTMLText, the query is not happening anymore

        // Build a list of HTMLText fields, merging all linked pages together.
        $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;
        }

PRs

@lekoala
Copy link
Contributor Author

lekoala commented Jun 22, 2023

same thing for SiteTreeLinkTracking

maybe i'm missing something, but these changes seem to save two queries :-)

GuySartorelli pushed a commit to silverstripe/silverstripe-cms that referenced this issue Aug 18, 2023
* Don't make query if not needed

See silverstripe/silverstripe-assets#557 for background

* add comment
@GuySartorelli
Copy link
Member

Both PRs are merged. Thanks for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants