mirror of
git://develop.git.wordpress.org/
synced 2025-02-27 18:13:00 +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: https://develop.svn.wordpress.org/trunk@14560 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b726ce95dc
commit
5d13bccc69
@ -405,11 +405,15 @@ function _sort_nav_menu_items($a, $b) {
|
|||||||
* @return mixed $items array of menu items, else false.
|
* @return mixed $items array of menu items, else false.
|
||||||
*/
|
*/
|
||||||
function wp_get_nav_menu_items( $menu, $args = array() ) {
|
function wp_get_nav_menu_items( $menu, $args = array() ) {
|
||||||
|
global $_wp_using_ext_object_cache;
|
||||||
|
|
||||||
$menu = wp_get_nav_menu_object( $menu );
|
$menu = wp_get_nav_menu_object( $menu );
|
||||||
|
|
||||||
if ( ! $menu )
|
if ( ! $menu )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
static $fetched = array();
|
||||||
|
|
||||||
$items = get_objects_in_term( $menu->term_id, 'nav_menu' );
|
$items = get_objects_in_term( $menu->term_id, 'nav_menu' );
|
||||||
|
|
||||||
if ( empty( $items ) )
|
if ( empty( $items ) )
|
||||||
@ -429,32 +433,35 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Get all posts and terms at once to prime the caches
|
// Get all posts and terms at once to prime the caches
|
||||||
$posts = array();
|
if ( empty($fetched[$menu->term_id]) || $_wp_using_ext_object_cache ) {
|
||||||
$terms = array();
|
$fetched[$menu->term_id] = true;
|
||||||
foreach ( $items as $item ) {
|
$posts = array();
|
||||||
$object_id = get_post_meta( $item->ID, '_menu_item_object_id', true );
|
$terms = array();
|
||||||
$object = get_post_meta( $item->ID, '_menu_item_object', true );
|
foreach ( $items as $item ) {
|
||||||
$type = get_post_meta( $item->ID, '_menu_item_type', true );
|
$object_id = get_post_meta( $item->ID, '_menu_item_object_id', true );
|
||||||
|
$object = get_post_meta( $item->ID, '_menu_item_object', true );
|
||||||
if ( 'post_type' == $type )
|
$type = get_post_meta( $item->ID, '_menu_item_type', true );
|
||||||
$posts[$object][] = $object_id;
|
|
||||||
elseif ( 'taxonomy' == $type)
|
if ( 'post_type' == $type )
|
||||||
$terms[$object][] = $object_id;
|
$posts[$object][] = $object_id;
|
||||||
}
|
elseif ( 'taxonomy' == $type)
|
||||||
|
$terms[$object][] = $object_id;
|
||||||
if ( !empty($posts) ) {
|
|
||||||
foreach ( array_keys($posts) as $post_type ) {
|
|
||||||
get_posts( array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false) );
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
unset($posts);
|
if ( !empty($posts) ) {
|
||||||
|
foreach ( array_keys($posts) as $post_type ) {
|
||||||
if ( !empty($terms) ) {
|
get_posts( array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false) );
|
||||||
foreach ( array_keys($terms) as $taxonomy ) {
|
}
|
||||||
get_terms($taxonomy, array('include' => $terms[$taxonomy]) );
|
|
||||||
}
|
}
|
||||||
|
unset($posts);
|
||||||
|
|
||||||
|
if ( !empty($terms) ) {
|
||||||
|
foreach ( array_keys($terms) as $taxonomy ) {
|
||||||
|
get_terms($taxonomy, array('include' => $terms[$taxonomy]) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($terms);
|
||||||
}
|
}
|
||||||
unset($terms);
|
|
||||||
|
|
||||||
$items = array_map( 'wp_setup_nav_menu_item', $items );
|
$items = array_map( 'wp_setup_nav_menu_item', $items );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user