From cc71a3e68a4da96b881f8e7a64ed201b40267b4a Mon Sep 17 00:00:00 2001 From: David Stoline Date: Mon, 11 Feb 2013 14:57:11 -0500 Subject: [PATCH 1/3] refactor menu_rebuild --- includes/menu.inc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/includes/menu.inc b/includes/menu.inc index 0d377d0d387..dcbe7440766 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -581,7 +581,7 @@ function _menu_translate(&$router_item, $map, $to_arg = FALSE) { $router_item['href'] = implode('/', $link_map); $router_item['options'] = array(); _menu_check_access($router_item, $map); - + // For performance, don't localize an item the user can't access. if ($router_item['access']) { _menu_item_localize($router_item, $map); @@ -1695,31 +1695,31 @@ function menu_cache_clear_all() { function menu_rebuild() { if (!lock_acquire('menu_rebuild')) { // Wait for another request that is already doing this work. - // We choose to block here since otherwise the router item may not + // We choose to block here since otherwise the router item may not // be avaiable in menu_execute_active_handler() resulting in a 404. - lock_wait('menu_rebuild'); return FALSE; } // Encapsulate the rebuild in a transaction. db_query('BEGIN'); - $menu = menu_router_build(TRUE); - _menu_navigation_links_rebuild($menu); - // Clear the menu, page and block caches. - menu_cache_clear_all(); - _menu_clear_page_cache(); - if (defined('MAINTENANCE_MODE')) { variable_set('menu_rebuild_needed', TRUE); } else { variable_del('menu_rebuild_needed'); } + + $menu = menu_router_build(TRUE); + _menu_navigation_links_rebuild($menu); + // Clear the menu, page and block caches. + menu_cache_clear_all(); + _menu_clear_page_cache(); + lock_release('menu_rebuild'); - + db_query('COMMIT'); - + return TRUE; } @@ -1904,7 +1904,7 @@ function _menu_delete_item($item, $force = FALSE) { * - router_path: The path of the relevant router item. * * @return - * The mlid of the saved menu link, or FALSE if the menu link could not be + * The mlid of the saved menu link, or FALSE if the menu link could not be * saved. */ function menu_link_save(&$item) { From 633d0220e0a7b76b4a00c4109f5aa54a77bf8cde Mon Sep 17 00:00:00 2001 From: David Stoline Date: Mon, 11 Feb 2013 15:55:16 -0500 Subject: [PATCH 2/3] adding back whitespace --- includes/menu.inc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/menu.inc b/includes/menu.inc index dcbe7440766..42fcdec2ceb 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -581,7 +581,7 @@ function _menu_translate(&$router_item, $map, $to_arg = FALSE) { $router_item['href'] = implode('/', $link_map); $router_item['options'] = array(); _menu_check_access($router_item, $map); - + // For performance, don't localize an item the user can't access. if ($router_item['access']) { _menu_item_localize($router_item, $map); @@ -1695,7 +1695,7 @@ function menu_cache_clear_all() { function menu_rebuild() { if (!lock_acquire('menu_rebuild')) { // Wait for another request that is already doing this work. - // We choose to block here since otherwise the router item may not + // We choose to block here since otherwise the router item may not // be avaiable in menu_execute_active_handler() resulting in a 404. return FALSE; } @@ -1717,9 +1717,9 @@ function menu_rebuild() { _menu_clear_page_cache(); lock_release('menu_rebuild'); - + db_query('COMMIT'); - + return TRUE; } @@ -1904,7 +1904,7 @@ function _menu_delete_item($item, $force = FALSE) { * - router_path: The path of the relevant router item. * * @return - * The mlid of the saved menu link, or FALSE if the menu link could not be + * The mlid of the saved menu link, or FALSE if the menu link could not be * saved. */ function menu_link_save(&$item) { From 951b98763ef6b8f80335bc70a0792b9ff788f11e Mon Sep 17 00:00:00 2001 From: David Stoline Date: Mon, 11 Feb 2013 16:29:41 -0500 Subject: [PATCH 3/3] Rework documentation for menu_rebuild lock implementation. --- includes/menu.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/menu.inc b/includes/menu.inc index 42fcdec2ceb..7269e5ed85a 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -1694,9 +1694,9 @@ function menu_cache_clear_all() { */ function menu_rebuild() { if (!lock_acquire('menu_rebuild')) { - // Wait for another request that is already doing this work. - // We choose to block here since otherwise the router item may not - // be avaiable in menu_execute_active_handler() resulting in a 404. + // In high traffic situations, calling lock_wait() here, as core does, can + // cause processes to stack up that could result in an outage. Since the + // work below is in a transaction the lock_wait() is unnecessary. return FALSE; }