Skip to content

Commit

Permalink
Improve query speed for IslandoraUtils::getTermForUri()
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall committed Jan 17, 2025
1 parent 9ca6ba0 commit fca5fcd
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/IslandoraUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,24 +261,19 @@ public function getTermForUri($uri) {
// Add field_external_uri.
$fields[] = self::EXTERNAL_URI_FIELD;

$query = $this->entityTypeManager->getStorage('taxonomy_term')->getQuery();

$orGroup = $query->orConditionGroup();
$storage = $this->entityTypeManager->getStorage('taxonomy_term');
foreach ($fields as $field) {
$orGroup->condition("$field.uri", $uri);
}

$results = $query
->accessCheck(TRUE)
->condition($orGroup)
->execute();

if (empty($results)) {
return NULL;
$query = $storage->getQuery();
$results = $query
->accessCheck(TRUE)
->condition("$field.uri", $uri)
->execute();
if (!empty($results)) {
return $storage->load(reset($results));
}
}

return $this->entityTypeManager->getStorage('taxonomy_term')
->load(reset($results));
return NULL;
}

/**
Expand Down

0 comments on commit fca5fcd

Please sign in to comment.