Mercurial > defr > drupal > core
diff modules/book/book.module @ 5:2427550111ae 6.2
Drupal 6.2
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:30:08 +0100 |
parents | c1f4ac30525a |
children | fff6d4c8c043 |
line wrap: on
line diff
--- a/modules/book/book.module Tue Dec 23 14:29:21 2008 +0100 +++ b/modules/book/book.module Tue Dec 23 14:30:08 2008 +0100 @@ -1,5 +1,5 @@ <?php -// $Id: book.module,v 1.454.2.2 2008/02/13 11:20:47 goba Exp $ +// $Id: book.module,v 1.454.2.3 2008/03/25 14:03:02 goba Exp $ /** * @file @@ -1044,14 +1044,21 @@ function book_menu_subtree_data($item) { static $tree = array(); - $cid = 'links:'. $item['menu_name'] .':subtree:'. $item['mlid']; + // Generate a cache ID (cid) specific for this $menu_name and $item. + $cid = 'links:'. $item['menu_name'] .':subtree-cid:'. $item['mlid']; if (!isset($tree[$cid])) { $cache = cache_get($cid, 'cache_menu'); if ($cache && isset($cache->data)) { - $data = $cache->data; + // If the cache entry exists, it will just be the cid for the actual data. + // This avoids duplication of large amounts of data. + $cache = cache_get($cache->data, 'cache_menu'); + if ($cache && isset($cache->data)) { + $data = $cache->data; + } } - else { + // If the subtree data was not in the cache, $data will be NULL. + if (!isset($data)) { $match = array("menu_name = '%s'"); $args = array($item['menu_name']); $i = 1; @@ -1070,8 +1077,14 @@ $data['tree'] = menu_tree_data(db_query($sql, $args), array(), $item['depth']); $data['node_links'] = array(); menu_tree_collect_node_links($data['tree'], $data['node_links']); - // Cache the data. - cache_set($cid, $data, 'cache_menu'); + // Compute the real cid for book subtree data. + $tree_cid = 'links:'. $menu_name .':subtree-data:'. md5(serialize($data)); + // Cache the data, if it is not already in the cache. + if (!cache_get($tree_cid, 'cache_menu')) { + cache_set($tree_cid, $data, 'cache_menu'); + } + // Cache the cid of the (shared) data using the menu and item-specific cid. + cache_set($cid, $tree_cid, 'cache_menu'); } // Check access for the current user to each item in the tree. menu_tree_check_access($data['tree'], $data['node_links']);