WordPress.org

Make WordPress Core

Changeset 34127


Ignore:
Timestamp:
09/14/2015 07:24:59 PM (4 years ago)
Author:
wonderboymusic
Message:

In WP_Media_List_Table, fetch all pending comment counts at once, instead of for each row in the loop.

See #11381.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r33810 r34127  
    99 */
    1010class WP_Media_List_Table extends WP_List_Table {
     11    /**
     12     * Store the pending comment count for each post
     13     *
     14     * @access public
     15     * @since 4.4.0
     16     * @var array
     17     */
     18    public $pending_count = array();
    1119
    1220    private $detached;
     
    150158            /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
    151159            do_action( 'restrict_manage_posts', $this->screen->post_type );
    152            
     160
    153161            submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
    154162        }
     
    482490        echo '<div class="post-com-count-wrapper">';
    483491
    484         $pending_comments = get_pending_comments_num( $post->ID );
     492        if ( isset( $this->pending_count[ $post->ID ] ) ) {
     493            $pending_comments = $this->pending_count[ $post->ID ];
     494        } else {
     495            $pending_comments = get_pending_comments_num( $post->ID );
     496        }
     497
    485498        $this->comments_bubble( $post->ID, $pending_comments );
    486499
     
    549562     */
    550563    public function display_rows() {
    551         global $post;
     564        global $post, $wp_query;
     565
     566        $post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
     567        reset( $wp_query->posts );
     568
     569        $this->pending_count = get_pending_comments_num( $post_ids );
    552570
    553571        add_filter( 'the_title','esc_html' );
Note: See TracChangeset for help on using the changeset viewer.