- Issue created by @h1nds1ght
- 🇩🇪Germany Anybody Porta Westfalica
Would it be possible to reroll this as MR and provide a test to show the results do not change?
The service TaxonomyManagerHelper.php
has a function vocabularyIsEmpty
which is used to determine if a vocabulary with a specific vid
has any terms. This is executed on every page load of a TaxonomyManagerForm
and executes a full loadTree
, which is very expensive if you have a large vocabulary.
Visit any TaxonomyManagerForm
of a vocabulary , buildForm
then executes vocabularyIsEmpty
Replace loadTree
in TaxonomyManagerHelper.php
with an entity query, i.e.
diff --git a/src/TaxonomyManagerHelper.php b/src/TaxonomyManagerHelper.php
index 4070426..5923054 100644
--- a/src/TaxonomyManagerHelper.php
+++ b/src/TaxonomyManagerHelper.php
@@ -86,7 +86,12 @@ class TaxonomyManagerHelper {
public function vocabularyIsEmpty($vid) {
/** @var \Drupal\taxonomy\TermStorageInterface $term_storage */
$term_storage = $this->taxonomyTypeManager;
- return empty($term_storage->loadTree($vid));
+ return !$term_storage->getQuery()
+ ->accessCheck(FALSE)
+ ->condition('vid', $vid)
+ ->range(0, 1)
+ ->count()
+ ->execute();
}
/**
Active
2.0
Code
It affects performance. It is often combined with the Needs profiling tag.
The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.
Would it be possible to reroll this as MR and provide a test to show the results do not change?