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

Improve query speed for IslandoraUtils::getTermForUri() #1067

Merged
merged 2 commits into from
Mar 5, 2025

Conversation

joecorall
Copy link
Member

@joecorall joecorall commented Jan 17, 2025

Continuation of #997
Closes Islandora/documentation#2272

What does this Pull Request do?

Improve performance for IslandoraUtils::getTermForUri(). Sets the new approach as the default, allowing sites to revert to the current, single query approach with a config checkbox in Islandora settings.

How should this be tested?

Made a simple drush script

$ cat << EOF > scripts/1067.php
<?php

\$i = 0;
while (++\$i < 100) {
  \$term = \Drupal::service('islandora.utils')->getTermForUri("http://purl.org/coar/resource_type/c_18cc");
}
EOF

Then ran it and it took 17s to complete

$ time drush scr scripts/1067.php 
real    0m 17.46s
user    0m 0.52s
sys     0m 0.38s

Applied this PR and ran again and execution dropped to 1s

$ cd path/to/drupal/root
$ jq '.extra.patches."drupal/islandora" += {"Speed up getTermForUri": "https://github.com/Islandora/islandora/pull/1067.patch"}' composer.json > composer.json.tmp
$ mv composer.json.tmp composer.json
$ composer install
$ drush updb -y
$ time drush scr scripts/1067.php 
real    0m 0.99s
user    0m 0.46s
sys     0m 0.18s

It's definitely the query here causing the slowdown, as if I replace the query with $results = [12]; I get similar 1s executions.

Here's the query that entityTypeManager is running:

SELECT t.revision_id, tid FROM taxonomy_term_data t
LEFT JOIN taxonomy_term__field_authority_link a ON a.entity_id = t.tid
LEFT JOIN taxonomy_term__field_external_uri e ON e.entity_id = t.tid
WHERE (a.field_authority_link_uri = 'http://purl.org/coar/resource_type/c_18cc') or (e.field_external_uri_uri = 'http://purl.org/coar/resource_type/c_18cc')

I think due to the orGroup this is slowing down these queries. It appears be more efficient to run several queries.

Documentation Status

  • Does this change existing behaviour that's currently documented?
  • Does this change require new pages or sections of documentation?
  • Who does this need to be documented for?
  • Associated documentation pull request(s): ___ or documentation issue ___

Additional Notes:

Any additional information that you think would be helpful when reviewing this
PR.

Interested parties

Tag (@ mention) interested parties or, if unsure, @Islandora/committers

@joecorall joecorall closed this Jan 22, 2025
@joecorall joecorall deleted the improve-query branch January 22, 2025 22:16
@joecorall joecorall restored the improve-query branch January 22, 2025 22:38
@joecorall joecorall reopened this Jan 22, 2025
@joecorall joecorall marked this pull request as draft February 26, 2025 17:50
@joecorall joecorall force-pushed the improve-query branch 4 times, most recently from f682537 to 1a9ecdb Compare February 27, 2025 17:39
@joecorall joecorall marked this pull request as ready for review February 27, 2025 18:03
@rbos
Copy link

rbos commented Mar 2, 2025

Can attest that this patch seems to improve general site responsiveness. Large collections load much faster.

@seth-shaw-asu seth-shaw-asu self-requested a review March 5, 2025 18:11
@seth-shaw-asu seth-shaw-asu merged commit 699c85c into 2.x Mar 5, 2025
21 of 27 checks passed
@seth-shaw-asu seth-shaw-asu deleted the improve-query branch March 5, 2025 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Cache terms returned by IslandoraUtils::getTermForUri()
4 participants