Skip to content
Snippets Groups Projects
Commit 8895f5cd authored by catch's avatar catch
Browse files

Issue #916388 by Berdir: Follow-up, improve menu_rebuild() performance.

parent ba89738c
No related branches found
No related tags found
No related merge requests found
......@@ -331,7 +331,7 @@ public function loadModuleAdminTasks() {
*/
protected function updateParentalStatus(EntityInterface $entity, $exclude = FALSE) {
// If plid == 0, there is nothing to update.
if ($entity->plid && ($parent_entity = $this->load(array($entity->plid)))) {
if ($entity->plid) {
// Check if at least one visible child exists in the table.
$query = entity_query($this->entityType);
$query
......@@ -345,9 +345,10 @@ protected function updateParentalStatus(EntityInterface $entity, $exclude = FALS
}
$parent_has_children = ((bool) $query->execute()) ? 1 : 0;
$parent_entity = reset($parent_entity);
$parent_entity->has_children = $parent_has_children;
$parent_entity->save();
db_update('menu_links')
->fields(array('has_children' => $parent_has_children))
->condition('mlid', $entity->plid)
->execute();
}
}
......@@ -416,8 +417,6 @@ protected function findParent(EntityInterface $entity, array $parent_candidates
$parent = FALSE;
$parent_path = substr($parent_path, 0, strrpos($parent_path, '/'));
// @todo Return to the previous method of cloning the entity query when
// http://drupal.org/node/1829942 is fixed.
$query = entity_query($this->entityType);
$query
->condition('mlid', $entity->id(), '<>')
......@@ -427,10 +426,9 @@ protected function findParent(EntityInterface $entity, array $parent_candidates
->condition('menu_name', $entity->menu_name)
->condition('link_path', $parent_path);
$count_query = clone $query;
$result = $query->execute();
// Only valid if we get a unique result.
if ($count_query->count()->execute() == 1) {
$result = $query->execute();
if (count($result) == 1) {
$parent = $this->load($result);
$parent = reset($parent);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment