diff --git a/includes/menu.inc b/includes/menu.inc index 8e26b6d..57a64b6 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -309,7 +309,7 @@ define('MENU_PREFERRED_LINK', '1cf698d64d1aa4b83907cf6ed55db3a7f8e92c91'); * actually exists. This list of 'masks' is built in menu_rebuild(). * * @param $parts - * An array of path parts; for the above example, + * An array of path parts; for the above example, * array('node', '12345', 'edit'). * * @return @@ -462,9 +462,19 @@ function menu_get_item($path = NULL, $router_item = NULL) { } $original_map = arg(NULL, $path); - $parts = array_slice($original_map, 0, MENU_MAX_PARTS); - $ancestors = menu_get_ancestors($parts); - $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc(); + // Since there is no limit to the length of $path, use a hash to keep it + // short yet unique. + $cid = "menu_item:" . hash('sha256', $path); + $cached = cache_get($cid, 'cache_menu'); + if (isset($cached->data)) { + $router_item = $cached->data; + } + else { + $parts = array_slice($original_map, 0, MENU_MAX_PARTS); + $ancestors = menu_get_ancestors($parts); + $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc(); + cache_set($cid, $router_item, 'cache_menu'); + } if ($router_item) { // Allow modules to alter the router item before it is translated and