Closed (duplicate)
Project:
Drupal core
Version:
7.x-dev
Component:
menu system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
7 Nov 2010 at 22:03 UTC
Updated:
8 Nov 2010 at 19:59 UTC
Attached you can find a patch for a lite performance improvement for menu_get_item(). menu_get_item() is frequently called.
Following code has been moved just before db_query_range():
$part = array_slice($original_map, 0, MENU_MAX_PARTS));
$ancestors = menu_get_ancestors($parts);
Resulting following code:
function menu_get_item($path = NULL, $router_item = NULL) {
$router_items = &drupal_static(__FUNCTION__);
if (!isset($path)) {
$path = $_GET['q'];
}
if (isset($router_item)) {
$router_items[$path] = $router_item;
}
if (!isset($router_items[$path])) {
$original_map = arg(NULL, $path);
// 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);
if ($cached = cache_get($cid, 'cache_menu')) {
$router_item = $cached->data;
}
else {
$ancestors = menu_get_ancestors(array_slice($original_map, 0, MENU_MAX_PARTS));
$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');
}
[...]
| Comment | File | Size | Author |
|---|---|---|---|
| menu_get_item_101107.patch | 1.12 KB | jpsoto |
Comments
Comment #1
jpsoto commentedComment #3
jpsoto commentedDuplicate #964822: Small optimization for menu_get_item()