Comments: Ignore the 'fields' parameter in the comment query cache.

`WP_Comment_Query` always queries runs an ID query, and so is unaffected
by the 'fields' parameter. As such, 'fields' can be ignored when building
a cache key for the results of the ID query.

Props spacedmonkey.
Fixes #41348.
Built from https://develop.svn.wordpress.org/trunk@41190


git-svn-id: http://core.svn.wordpress.org/trunk@41030 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2017-07-30 14:56:41 +00:00
parent e412ea2e6b
commit c657a2c060
2 changed files with 9 additions and 4 deletions

View File

@ -375,10 +375,15 @@ class WP_Comment_Query {
$this->meta_query_clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this );
}
// $args can include anything. Only use the args defined in the query_var_defaults to compute the key.
$key = md5( serialize( wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) ) ) );
$last_changed = wp_cache_get_last_changed( 'comment' );
/*
* Only use the args defined in the query_var_defaults to compute the key,
* but ignore 'fields', which does not affect query results.
*/
$_args = wp_array_slice_assoc( $this->query_vars, array_keys( $this->query_var_defaults ) );
unset( $_args['fields'] );
$key = md5( serialize( $_args ) );
$last_changed = wp_cache_get_last_changed( 'comment' );
$cache_key = "get_comments:$key:$last_changed";
$cache_value = wp_cache_get( $cache_key, 'comment' );

View File

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