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

See #11381.

Built from https://develop.svn.wordpress.org/trunk@34127


git-svn-id: http://core.svn.wordpress.org/trunk@34095 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-09-14 19:25:25 +00:00
parent dbe4a770d5
commit 4d33644373
2 changed files with 22 additions and 4 deletions

View File

@ -8,6 +8,14 @@
* @access private * @access private
*/ */
class WP_Media_List_Table extends WP_List_Table { class WP_Media_List_Table extends WP_List_Table {
/**
* Store the pending comment count for each post
*
* @access public
* @since 4.4.0
* @var array
*/
public $pending_count = array();
private $detached; private $detached;
@ -149,7 +157,7 @@ class WP_Media_List_Table extends WP_List_Table {
/** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */ /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
do_action( 'restrict_manage_posts', $this->screen->post_type ); do_action( 'restrict_manage_posts', $this->screen->post_type );
submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
} }
@ -481,7 +489,12 @@ class WP_Media_List_Table extends WP_List_Table {
public function column_comments( $post ) { public function column_comments( $post ) {
echo '<div class="post-com-count-wrapper">'; echo '<div class="post-com-count-wrapper">';
$pending_comments = get_pending_comments_num( $post->ID ); if ( isset( $this->pending_count[ $post->ID ] ) ) {
$pending_comments = $this->pending_count[ $post->ID ];
} else {
$pending_comments = get_pending_comments_num( $post->ID );
}
$this->comments_bubble( $post->ID, $pending_comments ); $this->comments_bubble( $post->ID, $pending_comments );
echo '</div>'; echo '</div>';
@ -548,7 +561,12 @@ class WP_Media_List_Table extends WP_List_Table {
* @global WP_Post $post * @global WP_Post $post
*/ */
public function display_rows() { public function display_rows() {
global $post; global $post, $wp_query;
$post_ids = wp_list_pluck( $wp_query->posts, 'ID' );
reset( $wp_query->posts );
$this->pending_count = get_pending_comments_num( $post_ids );
add_filter( 'the_title','esc_html' ); add_filter( 'the_title','esc_html' );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.4-alpha-34126'; $wp_version = '4.4-alpha-34127';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.