Ticket #18536: 18536.6.diff

File 18536.6.diff, 5.9 KB (added by scribu, 16 months ago)
  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index 6f7030a..af6d99d 100644
    function wp_debug_backtrace_summary( $ignore_class = null, $skip_frames = 0, $pr 
    37033703        else 
    37043704                return $caller; 
    37053705} 
     3706 
     3707/** 
     3708 * Retrieve ids that are not already present in the cache 
     3709 * 
     3710 * @since 3.4.0 
     3711 * 
     3712 * @param array $object_ids ID list 
     3713 * @param string $cache_key The cache bucket to check against 
     3714 * 
     3715 * @return array 
     3716 */ 
     3717function _get_non_cached_ids( $object_ids, $cache_key ) { 
     3718        $clean = array(); 
     3719        foreach ( $object_ids as $id ) { 
     3720                $id = (int) $id; 
     3721                if ( !wp_cache_get( $id, $cache_key ) ) { 
     3722                        $clean[] = $id; 
     3723                } 
     3724        } 
     3725 
     3726        return $clean; 
     3727} 
     3728 
  • wp-includes/pluggable.php

    diff --git wp-includes/pluggable.php wp-includes/pluggable.php
    index a6b7b47..08623f5 100644
    if ( !function_exists('cache_users') ) : 
    139139function cache_users( $user_ids ) { 
    140140        global $wpdb; 
    141141 
    142         $clean = array(); 
    143         foreach ( $user_ids as $id ) { 
    144                 $id = (int) $id; 
    145                 if ( !wp_cache_get( $id, 'users' ) ) { 
    146                         $clean[] = $id; 
    147                 } 
    148         } 
     142        $clean = _get_non_cached_ids( $user_ids, 'users' ); 
    149143 
    150144        if ( empty( $clean ) ) 
    151145                return; 
  • wp-includes/post-thumbnail-template.php

    diff --git wp-includes/post-thumbnail-template.php wp-includes/post-thumbnail-template.php
    index b4cf8bf..ab8941f 100644
    function update_post_thumbnail_cache() { 
    6464        } 
    6565 
    6666        if ( ! empty ( $thumb_ids ) ) { 
    67                 get_posts( array( 
    68                                 'update_post_term_cache' => false, 
    69                                 'include' => $thumb_ids, 
    70                                 'post_type' => 'attachment', 
    71                                 'post_status' => 'inherit', 
    72                                 'nopaging' => true 
    73                 ) ); 
     67                _prime_post_caches( $thumb_ids, false, true ); 
    7468        } 
    7569 
    7670        $wp_query->thumbnails_cached = true; 
  • wp-includes/post.php

    diff --git wp-includes/post.php wp-includes/post.php
    index 2bdd51b..10cd1f4 100644
    function _update_term_count_on_transition_post_status( $new_status, $old_status, 
    53205320                wp_update_term_count( $tt_ids, $taxonomy ); 
    53215321        } 
    53225322} 
     5323 
     5324/** 
     5325 * Adds any posts from the given ids to the cache that do not already exist in cache 
     5326 * 
     5327 * @since 3.4.0 
     5328 * 
     5329 * @access private 
     5330 * 
     5331 * @param array $post_ids ID list 
     5332 * @param bool $update_term_cache Whether to update the term cache. Default is true. 
     5333 * @param bool $update_meta_cache Whether to update the meta cache. Default is true. 
     5334 */ 
     5335function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) { 
     5336        global $wpdb; 
     5337 
     5338        $non_cached_ids = _get_non_cached_ids( $ids, 'posts' ); 
     5339        if ( !empty( $non_cached_ids ) ) { 
     5340                $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) ); 
     5341 
     5342                update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache ); 
     5343        } 
     5344} 
     5345 
  • wp-includes/query.php

    diff --git wp-includes/query.php wp-includes/query.php
    index bc6edea..df60a66 100644
    class WP_Query { 
    26062606                if ( !$q['no_found_rows'] && !empty($limits) ) 
    26072607                        $found_rows = 'SQL_CALC_FOUND_ROWS'; 
    26082608 
    2609                 $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 
    2610                 if ( !$q['suppress_filters'] ) 
    2611                         $this->request = apply_filters_ref_array('posts_request', array( $this->request, &$this ) ); 
     2609                $this->request = $old_request = "SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 
     2610 
     2611                if ( !$q['suppress_filters'] ) { 
     2612                        $this->request = apply_filters( 'posts_request', $this->request, $this ); 
     2613                } 
    26122614 
    26132615                if ( 'ids' == $q['fields'] ) { 
    26142616                        $this->posts = $wpdb->get_col($this->request); 
    class WP_Query { 
    26262628                        return $r; 
    26272629                } 
    26282630 
    2629                 $this->posts = $wpdb->get_results($this->request); 
     2631                if ( $old_request == $this->request && "$wpdb->posts.*" == $fields ) { 
     2632                        // First get the IDs and then fill in the objects 
     2633 
     2634                        $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 
     2635 
     2636                        $this->request = apply_filters( 'posts_request_ids', $this->request, $this ); 
     2637 
     2638                        $ids = $wpdb->get_col( $this->request ); 
     2639 
     2640                        if ( $ids ) { 
     2641                                $this->set_found_posts( $q, $limits ); 
     2642 
     2643                                _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 
     2644 
     2645                                $this->posts = array_map( 'get_post', $ids ); 
     2646                        } else { 
     2647                                $this->found_posts = $this->max_num_pages = 0; 
     2648                                $this->posts = array(); 
     2649                        } 
     2650                } else { 
     2651                        $this->posts = $wpdb->get_results( $this->request ); 
     2652                        $this->set_found_posts( $q, $limits ); 
     2653                } 
    26302654 
    26312655                // Raw results filter. Prior to status checks. 
    26322656                if ( !$q['suppress_filters'] ) 
    class WP_Query { 
    26452669                        $this->comment_count = count($this->comments); 
    26462670                } 
    26472671 
    2648                 if ( !$q['no_found_rows'] && !empty($limits) ) { 
    2649                         $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ); 
    2650                         $this->found_posts = $wpdb->get_var( $found_posts_query ); 
    2651                         $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 
    2652                         $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); 
    2653                 } 
    2654  
    26552672                // Check post status to determine if post should be displayed. 
    26562673                if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { 
    26572674                        $status = get_post_status($this->posts[0]); 
    class WP_Query { 
    27542771                return $this->posts; 
    27552772        } 
    27562773 
     2774        function set_found_posts( $q, $limits ) { 
     2775                global $wpdb; 
     2776 
     2777                if ( $q['no_found_rows'] || empty( $limits ) ) 
     2778                        return; 
     2779 
     2780                $this->found_posts = $wpdb->get_var( apply_filters( 'found_posts_query', 'SELECT FOUND_ROWS()', $this ) ); 
     2781                $this->found_posts = apply_filters( 'found_posts', $this->found_posts, $this ); 
     2782 
     2783                $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); 
     2784        } 
     2785 
    27572786        /** 
    27582787         * Set up the next post and iterate current post index. 
    27592788         *