Changeset 34599
- Timestamp:
- 09/26/2015 04:01:05 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-comment-query.php
r34561 r34599 139 139 * @since 4.4.0 `$parent__in` and `$parent__not_in` were added. 140 140 * @since 4.4.0 Order by `comment__in` was added. `$update_comment_meta_cache`, `$no_found_rows`, 141 * and `$hierarchical` were added.141 * `$hierarchical`, and `$update_comment_post_cache` were added. 142 142 * @access public 143 143 * … … 239 239 * @type bool $update_comment_meta_cache Whether to prime the metadata cache for found comments. 240 240 * Default true. 241 * @type bool $update_comment_post_cache Whether to prime the cache for comment posts. 242 * Default false. 241 243 * } 242 244 */ … … 282 284 'hierarchical' => false, 283 285 'update_comment_meta_cache' => true, 286 'update_comment_post_cache' => false, 284 287 ); 285 288 … … 413 416 $_comments[] = $_comment; 414 417 } 418 } 419 420 // Prime comment post caches. 421 if ( $this->query_vars['update_comment_post_cache'] ) { 422 $comment_post_ids = array(); 423 foreach ( $_comments as $_comment ) { 424 $comment_post_ids[] = $_comment->comment_post_ID; 425 } 426 427 _prime_post_caches( $comment_post_ids, false, false ); 415 428 } 416 429 -
trunk/src/wp-includes/class-wp-comment.php
r34595 r34599 158 158 */ 159 159 protected $children; 160 161 /** 162 * Post fields. 163 * 164 * @since 4.4.0 165 * @access protected 166 * @var array 167 */ 168 protected $post_fields = array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_content_filtered', 'post_parent', 'guid', 'menu_order', 'post_type', 'post_mime_type', 'comment_count' ); 160 169 161 170 /** … … 323 332 324 333 /** 325 * Whether a comment has post from which to retrieve magic properties 326 * 327 * @since 4.4.0 328 * @access public 329 * 330 * @param string $name 334 * Check whether a non-public property is set. 335 * 336 * If `$name` matches a post field, the comment post will be loaded and the post's value checked. 337 * 338 * @since 4.4.0 339 * @access public 340 * 341 * @param string $name Property name. 331 342 * @return bool 332 343 */ 333 344 public function __isset( $name ) { 334 if ( 335 0 === (int) $this->comment_post_ID 336 || property_exists( $this, $name ) 337 ) { 338 return; 339 } 340 341 $post = get_post( $this->comment_post_ID ); 342 if ( $post ) { 345 if ( in_array( $name, $this->post_fields ) && 0 !== (int) $this->comment_post_ID ) { 346 $post = get_post( $this->comment_post_ID ); 343 347 return property_exists( $post, $name ); 344 348 } … … 346 350 347 351 /** 348 * Magic getter for $post properties 352 * Magic getter. 353 * 354 * If `$name` matches a post field, the comment post will be loaded and the post's value returned. 349 355 * 350 356 * @since 4.4.0 … … 355 361 */ 356 362 public function __get( $name ) { 357 $post = get_post( $this->comment_post_ID );358 if ( $post ) {363 if ( in_array( $name, $this->post_fields ) ) { 364 $post = get_post( $this->comment_post_ID ); 359 365 return $post->$name; 360 366 } -
trunk/tests/phpunit/tests/comment.php
r34546 r34599 340 340 $this->assertEquals( array( $c3 ), array_values( wp_list_pluck( $children[ $c2 ]->get_children(), 'comment_ID' ) ) ); 341 341 } 342 343 /** 344 * @group 27571 345 */ 346 public function test_post_properties_should_be_lazyloaded() { 347 $p = $this->factory->post->create(); 348 349 $c = $this->factory->comment->create( array( 'comment_post_ID' => $p ) ); 350 351 $post = get_post( $p ); 352 $comment = get_comment( $c ); 353 354 $post_fields = array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_content_filtered', 'post_parent', 'guid', 'menu_order', 'post_type', 'post_mime_type', 'comment_count' ); 355 356 foreach ( $post_fields as $pf ) { 357 $this->assertTrue( isset( $comment->$pf ), $pf ); 358 $this->assertSame( $post->$pf, $comment->$pf, $pf ); 359 } 360 } 342 361 } -
trunk/tests/phpunit/tests/comment/query.php
r34569 r34599 2109 2109 $this->assertEqualSets( array(), array_values( wp_list_pluck( $q->comments[ $c1 ]->get_child( $c2 )->get_children( $args ), 'comment_ID' ) ) ); 2110 2110 } 2111 2112 /** 2113 * @ticket 27571 2114 */ 2115 public function test_update_comment_post_cache_should_be_disabled_by_default() { 2116 global $wpdb; 2117 2118 $p = $this->factory->post->create(); 2119 $c = $this->factory->comment->create( array( 'comment_post_ID' => $p ) ); 2120 2121 $q = new WP_Comment_Query( array( 2122 'post_ID' => $p, 2123 ) ); 2124 2125 $num_queries = $wpdb->num_queries; 2126 $this->assertTrue( isset( $q->comments[0]->post_name ) ); 2127 $this->assertSame( $num_queries + 1, $wpdb->num_queries ); 2128 } 2129 2130 /** 2131 * @ticket 27571 2132 */ 2133 public function test_should_respect_update_comment_post_cache_true() { 2134 global $wpdb; 2135 2136 $p = $this->factory->post->create(); 2137 $c = $this->factory->comment->create( array( 'comment_post_ID' => $p ) ); 2138 2139 $q = new WP_Comment_Query( array( 2140 'post_ID' => $p, 2141 'update_comment_post_cache' => true, 2142 ) ); 2143 2144 $num_queries = $wpdb->num_queries; 2145 $this->assertTrue( isset( $q->comments[0]->post_name ) ); 2146 $this->assertSame( $num_queries, $wpdb->num_queries ); 2147 } 2111 2148 }
Note: See TracChangeset
for help on using the changeset viewer.