Commit ea064e3e authored by webchick's avatar webchick

#643984 by catch: Cache results of menu_get_item(). This makes it possible to...

#643984 by catch: Cache results of menu_get_item(). This makes it possible to serve a page in Drupal 7 with no hits to the database when using alternate caching backends.
parent 37b78e02
......@@ -403,13 +403,17 @@ 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_select('menu_router')
->fields('menu_router')
->condition('path', $ancestors, 'IN')
->orderBy('fit', 'DESC')
->range(0, 1)
->addTag('menu_get_item')
->execute()->fetchAssoc();
// Since there is no limit to the length of $path, but the cids are
// restricted to 255 characters, use md5() to keep it short yet unique.
$cid = 'menu_item:' . md5($path);
if ($cached = cache_get($cid, 'cache_menu')) {
$router_item = $cached->data;
}
else {
$router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc();
cache_set($cid, $router_item, 'cache_menu');
}
if ($router_item) {
$map = _menu_translate($router_item, $original_map);
$router_item['original_map'] = $original_map;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment