Changeset 34268
- Timestamp:
- 09/17/2015 07:29:46 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-comment-query.php
r34212 r34268 95 95 * @since 4.2.0 96 96 * @since 4.4.0 `$parent__in` and `$parent__not_in` were added. 97 * @since 4.4.0 Order by `comment__in` was added. 97 * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache` was added. 98 98 * @access public 99 99 * … … 162 162 * @type array $type__not_in Exclude comments from a given array of comment types. Default empty. 163 163 * @type int $user_id Include comments for a specific user ID. Default empty. 164 * @type bool $update_comment_meta_cache Whether to prime the metadata cache for found comments. 165 * Default true. 164 166 * } 165 167 */ … … 202 204 'meta_query' => '', 203 205 'date_query' => null, // See WP_Date_Query 206 'update_comment_meta_cache' => true, 204 207 ); 205 208 … … 699 702 wp_cache_add( $cache_key, $comments, 'comment' ); 700 703 if ( '*' === $fields ) { 701 update_comment_cache( $comments );704 update_comment_cache( $comments, $this->query_vars['update_comment_meta_cache'] ); 702 705 } 703 706 -
trunk/src/wp-includes/comment-functions.php
r34253 r34268 2358 2358 * 2359 2359 * @since 2.3.0 2360 * 2361 * @param array $comments Array of comment row objects 2362 */ 2363 function update_comment_cache($comments) { 2360 * @since 4.4.0 Introduced the `$update_meta_cache` parameter. 2361 * 2362 * @param array $comments Array of comment row objects 2363 * @param bool $update_meta_cache Whether to update commentmeta cache. Default true. 2364 */ 2365 function update_comment_cache( $comments, $update_meta_cache = true ) { 2364 2366 foreach ( (array) $comments as $comment ) 2365 2367 wp_cache_add($comment->comment_ID, $comment, 'comment'); 2368 2369 if ( $update_meta_cache ) { 2370 // Avoid `wp_list_pluck()` in case `$comments` is passed by reference. 2371 $comment_ids = array(); 2372 foreach ( $comments as $comment ) { 2373 $comment_ids[] = $comment->comment_ID; 2374 } 2375 update_meta_cache( 'comment', $comment_ids ); 2376 } 2366 2377 } 2367 2378 -
trunk/tests/phpunit/tests/comment/metaCache.php
r33926 r34268 4 4 protected $i = 0; 5 5 protected $queries = 0; 6 7 /** 8 * @ticket 16894 9 */ 10 public function test_update_comment_meta_cache_should_default_to_true() { 11 global $wpdb; 12 13 $p = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 14 $comment_ids = $this->factory->comment->create_post_comments( $p, 3 ); 15 16 foreach ( $comment_ids as $cid ) { 17 update_comment_meta( $cid, 'foo', 'bar' ); 18 } 19 20 $q = new WP_Comment_Query( array( 21 'post_ID' => $p, 22 ) ); 23 24 $num_queries = $wpdb->num_queries; 25 foreach ( $comment_ids as $cid ) { 26 get_comment_meta( $cid, 'foo', 'bar' ); 27 } 28 29 $this->assertSame( $num_queries, $wpdb->num_queries ); 30 } 31 32 /** 33 * @ticket 16894 34 */ 35 public function test_update_comment_meta_cache_true() { 36 global $wpdb; 37 38 $p = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 39 $comment_ids = $this->factory->comment->create_post_comments( $p, 3 ); 40 41 foreach ( $comment_ids as $cid ) { 42 update_comment_meta( $cid, 'foo', 'bar' ); 43 } 44 45 $q = new WP_Comment_Query( array( 46 'post_ID' => $p, 47 'update_comment_meta_cache' => true, 48 ) ); 49 50 $num_queries = $wpdb->num_queries; 51 foreach ( $comment_ids as $cid ) { 52 get_comment_meta( $cid, 'foo', 'bar' ); 53 } 54 55 $this->assertSame( $num_queries, $wpdb->num_queries ); 56 } 57 58 /** 59 * @ticket 16894 60 */ 61 public function test_update_comment_meta_cache_false() { 62 global $wpdb; 63 64 $p = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 65 $comment_ids = $this->factory->comment->create_post_comments( $p, 3 ); 66 67 foreach ( $comment_ids as $cid ) { 68 update_comment_meta( $cid, 'foo', 'bar' ); 69 } 70 71 $q = new WP_Comment_Query( array( 72 'post_ID' => $p, 73 'update_comment_meta_cache' => false, 74 ) ); 75 76 $num_queries = $wpdb->num_queries; 77 foreach ( $comment_ids as $cid ) { 78 get_comment_meta( $cid, 'foo', 'bar' ); 79 } 80 81 $this->assertSame( $num_queries + 3, $wpdb->num_queries ); 82 } 6 83 7 84 public function test_comment_meta_cache() {
Note: See TracChangeset
for help on using the changeset viewer.