Allow turning off object_term and postmeta cache updates. Turn off object_term updates in the wp_get_nav_menu_items() get_posts() query to avoid useless taxonomy query.

git-svn-id: http://svn.automattic.com/wordpress/trunk@14528 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-05-10 00:58:39 +00:00
parent 616bc49e04
commit 66502fba1a
3 changed files with 16 additions and 6 deletions

View File

@ -413,7 +413,8 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
$items = get_objects_in_term( $menu->term_id, 'nav_menu' );
if ( ! empty( $items ) ) {
$defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true );
$defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true,
'update_post_term_cache' => false);
$args = wp_parse_args( $args, $defaults );
if ( count( $items ) > 1 )
$args['include'] = implode( ',', $items );

View File

@ -4003,9 +4003,11 @@ function clean_page_cache($id) {
* @uses update_postmeta_cache()
*
* @param array $posts Array of Post objects
* @param string $post_type The post type of the posts in $posts
* @param string $post_type The post type of the posts in $posts. Default is 'post'.
* @param bool $update_term_cache Whether to update the term cache. Default is true.
* @param bool $update_meta_cache Whether to update the meta cache. Default is true.
*/
function update_post_caches(&$posts, $post_type = 'post') {
function update_post_caches(&$posts, $post_type = 'post', $update_term_cache = true, $update_meta_cache = true) {
// No point in doing all this work if we didn't match any posts.
if ( !$posts )
return;
@ -4019,9 +4021,10 @@ function update_post_caches(&$posts, $post_type = 'post') {
if ( empty($post_type) )
$post_type = 'post';
if ( !is_array($post_type) && 'any' != $post_type )
if ( !is_array($post_type) && 'any' != $post_type && $update_term_cache )
update_object_term_cache($post_ids, $post_type);
if ( $update_meta_cache )
update_postmeta_cache($post_ids);
}

View File

@ -1621,6 +1621,12 @@ class WP_Query {
if ( !isset($q['cache_results']) )
$q['cache_results'] = true;
if ( !isset($q['update_post_term_cache']) )
$q['update_post_term_cache'] = true;
if ( !isset($q['update_post_meta_cache']) )
$q['update_post_meta_cache'] = true;
if ( !isset($q['post_type']) ) {
if ( $this->is_search )
$q['post_type'] = 'any';
@ -2504,7 +2510,7 @@ class WP_Query {
}
if ( $q['cache_results'] )
update_post_caches($this->posts, $post_type);
update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']);
if ( $this->post_count > 0 ) {
$this->post = $this->posts[0];