Make WordPress Core

Ticket #18536: 18536.5.diff

File 18536.5.diff, 5.4 KB (added by prettyboymp, 13 years ago)

introduce _prime_post_caches as separate function

  • wp-includes/post.php

     
    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 * @param array $post_ids ID list
     5331 * @param bool $update_term_cache Whether to update the term cache. Default is true.
     5332 * @param bool $update_meta_cache Whether to update the meta cache. Default is true.
     5333 */
     5334function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) {
     5335        global $wpdb;
     5336       
     5337        $non_cached_ids = _get_non_cached_ids( $ids, 'posts' );
     5338        if ( !empty( $non_cached_ids ) ) {
     5339                $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) );
     5340                update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
     5341        }
     5342}
     5343 No newline at end of file
  • wp-includes/functions.php

     
    36993699        else
    37003700                return $caller;
    37013701}
     3702
     3703/**
     3704 * Retrieve ids that are not already present in the cache
     3705 *
     3706 * @since 3.4.0
     3707 *
     3708 * @param array $object_ids ID list
     3709 * @param string $cache_key The cache bucket to check against
     3710 *
     3711 * @return array
     3712 */
     3713function _get_non_cached_ids( $object_ids, $cache_key ) {
     3714        $clean = array();
     3715        foreach ( $object_ids as $id ) {
     3716                $id = (int) $id;
     3717                if ( !wp_cache_get( $id, $cache_key ) ) {
     3718                        $clean[] = $id;
     3719                }
     3720        }
     3721
     3722        return $clean;
     3723}
     3724
  • wp-includes/query.php

     
    19511951                $fields = '';
    19521952                $post_status_join = false;
    19531953                $page = 1;
     1954                $expand_ids = false;
    19541955
    19551956                if ( isset( $q['caller_get_posts'] ) ) {
    19561957                        _deprecated_argument( 'WP_Query', '3.1', __( '"caller_get_posts" is deprecated. Use "ignore_sticky_posts" instead.' ) );
     
    25972598                                $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : '';
    25982599                }
    25992600
     2601                if ( "$wpdb->posts.*" == $fields ) {
     2602                        $fields = "$wpdb->posts.ID";
     2603                        $expand_ids = true;
     2604                }
     2605
    26002606                if ( ! empty($groupby) )
    26012607                        $groupby = 'GROUP BY ' . $groupby;
    26022608                if ( !empty( $orderby ) )
     
    26262632                        return $r;
    26272633                }
    26282634
    2629                 $this->posts = $wpdb->get_results($this->request);
     2635                if ( $expand_ids ) {
     2636                        $ids = $wpdb->get_col( $this->request );
    26302637
     2638                        if ( $ids ) {
     2639                                $this->set_found_posts( $q, $limits );
     2640
     2641                                _prime_post_caches($ids, $q['update_post_term_cache'], $q['update_post_meta_cache']);
     2642
     2643                                $this->posts = array_map( 'get_post', $ids );
     2644                        } else {
     2645                                $this->found_posts = $this->max_num_pages = 0;
     2646                                $this->posts = array();
     2647                        }
     2648                } else {
     2649                        $this->posts = $wpdb->get_results( $this->request );
     2650                        $this->set_found_posts( $q, $limits );
     2651                }
     2652
    26312653                // Raw results filter. Prior to status checks.
    26322654                if ( !$q['suppress_filters'] )
    26332655                        $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) );
     
    26452667                        $this->comment_count = count($this->comments);
    26462668                }
    26472669
    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 
    26552670                // Check post status to determine if post should be displayed.
    26562671                if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) {
    26572672                        $status = get_post_status($this->posts[0]);
     
    27542769                return $this->posts;
    27552770        }
    27562771
     2772        function set_found_posts( $q, $limits ) {
     2773                global $wpdb;
     2774
     2775                if ( $q['no_found_rows'] || empty( $limits ) )
     2776                        return;
     2777
     2778                $found_posts_query = apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', $this ) );
     2779                $this->found_posts = $wpdb->get_var( $found_posts_query );
     2780                $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, $this ) );
     2781                $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] );
     2782        }
     2783
    27572784        /**
    27582785         * Set up the next post and iterate current post index.
    27592786         *
  • wp-includes/formatting.php

     
    30193019        $urls_to_ping = array_map( 'esc_url_raw', $urls_to_ping );
    30203020        $urls_to_ping = implode( "\n", $urls_to_ping );
    30213021        return apply_filters( 'sanitize_trackback_urls', $urls_to_ping, $to_ping );
    3022 }
     3022}
     3023 No newline at end of file
  • wp-includes/pluggable.php

     
    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;