WordPress.org

Make WordPress Core

Ticket #13989: 13989.diff

File 13989.diff, 2.3 KB (added by dd32, 8 years ago)
  • wp-includes/default-widgets.php

     
    643643                        $number = 5;
    644644                else if ( $number < 1 )
    645645                        $number = 1;
     646                $comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );
    646647
    647                 $comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );
     648                $post_ids = array();
     649                foreach ( (array)$comments as $comment )
     650                        $post_ids[] = $comment->comment_post_ID;
     651                cache_posts($post_ids, false, false);
     652
    648653                $output .= $before_widget;
    649654                if ( $title )
    650655                        $output .= $before_title . $title . $after_title;
  • wp-includes/post.php

     
    41284128}
    41294129
    41304130/**
     4131 * Updates the post cache for a list of post IDs
     4132 *
     4133 * Performs a SQL query to retrieve any uncached posts in the gived post_ids list and cache them.
     4134 * Therefor, the function, which calls this function, doesn't cause unnecessary SQL queries from get_post().
     4135 *
     4136 * @package WordPress
     4137 * @subpackage Cache
     4138 * @since 3.1
     4139 *
     4140 * @param array $post_ids List of post IDs.
     4141 * @param bool $update_term_cache if the Term Cache should be updated for the given posts
     4142 * @param bool $update_postmeta_cache if the Post Meta Cache should be updated for the given posts
     4143 * @return null Doesnt return anything
     4144 */
     4145function cache_posts($post_ids, $update_term_cache = true, $update_postmeta_cache = true) {
     4146        // No point in loading posts already in memory
     4147        foreach ( (array) $post_ids as $key => $id )
     4148                if ( wp_cache_get($id, 'posts') )
     4149                        unset($post_ids[$key]);
     4150
     4151        // No point in doing all this work if all posts are in memory
     4152        if ( empty($post_ids) )
     4153                return;
     4154
     4155        get_posts( array(
     4156                                         'post__in' => $post_ids,
     4157                                         'post_type' => 'any',
     4158                                         'post_status' => 'any',
     4159                                         'update_post_term_cache' => $update_term_cache,
     4160                                         'update_post_meta_cache' => $update_postmeta_cache,
     4161                                         'numberposts' => -1,
     4162                                         'orderby' => 'none',
     4163                                         'suppress_filters' => true
     4164                                ));     
     4165}
     4166
     4167/**
    41314168 * Will clean the attachment in the cache.
    41324169 *
    41334170 * Cleaning means delete from the cache. Optionaly will clean the term