mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
Skip building the query in wp_count_posts() if cached results are used.
props MikeHansenMe. fixes #30928. Built from https://develop.svn.wordpress.org/trunk@31058 git-svn-id: http://core.svn.wordpress.org/trunk@31039 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
da5b68a17e
commit
7685e9dc97
@ -2351,6 +2351,12 @@ function wp_count_posts( $type = 'post', $perm = '' ) {
|
||||
|
||||
$cache_key = _count_posts_cache_key( $type, $perm );
|
||||
|
||||
$counts = wp_cache_get( $cache_key, 'counts' );
|
||||
if ( false !== $counts ) {
|
||||
/** This filter is documented in wp-includes/post.php */
|
||||
return apply_filters( 'wp_count_posts', $counts, $type, $perm );
|
||||
}
|
||||
|
||||
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
|
||||
if ( 'readable' == $perm && is_user_logged_in() ) {
|
||||
$post_type_object = get_post_type_object($type);
|
||||
@ -2362,18 +2368,16 @@ function wp_count_posts( $type = 'post', $perm = '' ) {
|
||||
}
|
||||
$query .= ' GROUP BY post_status';
|
||||
|
||||
$counts = wp_cache_get( $cache_key, 'counts' );
|
||||
if ( false === $counts ) {
|
||||
$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
|
||||
$counts = array_fill_keys( get_post_stati(), 0 );
|
||||
$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
|
||||
$counts = array_fill_keys( get_post_stati(), 0 );
|
||||
|
||||
foreach ( $results as $row )
|
||||
$counts[ $row['post_status'] ] = $row['num_posts'];
|
||||
|
||||
$counts = (object) $counts;
|
||||
wp_cache_set( $cache_key, $counts, 'counts' );
|
||||
foreach ( $results as $row ) {
|
||||
$counts[ $row['post_status'] ] = $row['num_posts'];
|
||||
}
|
||||
|
||||
$counts = (object) $counts;
|
||||
wp_cache_set( $cache_key, $counts, 'counts' );
|
||||
|
||||
/**
|
||||
* Modify returned post counts by status for the current post type.
|
||||
*
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.2-alpha-31057';
|
||||
$wp_version = '4.2-alpha-31058';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user