mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
Don't prime menu item cache if a persistent cache is being used. Prime the menu item cache only on the first call to wp_get_nav_menu_items(). Avoids unneeded queries when wp_get_nav_menu_items() is called repeatedly. see #12734
git-svn-id: http://svn.automattic.com/wordpress/trunk@14560 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2b930efb74
commit
02058305b5
@ -405,11 +405,15 @@ function _sort_nav_menu_items($a, $b) {
|
||||
* @return mixed $items array of menu items, else false.
|
||||
*/
|
||||
function wp_get_nav_menu_items( $menu, $args = array() ) {
|
||||
global $_wp_using_ext_object_cache;
|
||||
|
||||
$menu = wp_get_nav_menu_object( $menu );
|
||||
|
||||
if ( ! $menu )
|
||||
return false;
|
||||
|
||||
static $fetched = array();
|
||||
|
||||
$items = get_objects_in_term( $menu->term_id, 'nav_menu' );
|
||||
|
||||
if ( empty( $items ) )
|
||||
@ -429,6 +433,8 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
|
||||
return false;
|
||||
|
||||
// Get all posts and terms at once to prime the caches
|
||||
if ( empty($fetched[$menu->term_id]) || $_wp_using_ext_object_cache ) {
|
||||
$fetched[$menu->term_id] = true;
|
||||
$posts = array();
|
||||
$terms = array();
|
||||
foreach ( $items as $item ) {
|
||||
@ -455,6 +461,7 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
|
||||
}
|
||||
}
|
||||
unset($terms);
|
||||
}
|
||||
|
||||
$items = array_map( 'wp_setup_nav_menu_item', $items );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user