--- a/src/Plugin/facets/hierarchy/Taxonomy.php 2026-05-26 12:38:32.318690849 +0200 +++ b/src/Plugin/facets/hierarchy/Taxonomy.php 2026-05-26 12:38:46.819954029 +0200 @@ -125,14 +125,23 @@ * {@inheritdoc} */ public function getChildIds(array $ids) { + if (empty($ids)) { + return []; + } + $query = \Drupal::database()->select('taxonomy_term_field_data', 'td'); + $query->join('taxonomy_term__parent', 'th', '[td].[tid] = [th].[entity_id]'); + $query->addField('td', 'tid'); + $query->addField('th', 'parent_target_id'); + $query->condition('[th].[parent_target_id]', $ids, 'IN'); + $query->condition('[td].[default_langcode]', 1); + $query->orderBy('[td].[weight]'); + $query->orderBy('[td].[name]'); + $rows = $query->execute()->fetchAll(); + $parents = []; - foreach ($ids as $id) { - $terms = $this->getTermStorage()->loadChildren($id); - $parents[$id] = array_filter(array_values(array_map(function ($it) { - return $it->id(); - }, $terms))); + foreach ($rows as $row) { + $parents[$row->parent_target_id][] = (int) $row->tid; } - $parents = array_filter($parents); return $parents; }