Changeset 55749
- Timestamp:
- 05/11/2023 12:25:51 PM (20 months ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-comments-list-table.php
r55732 r55749 166 166 167 167 if ( is_array( $_comments ) ) { 168 update_comment_cache( $_comments );169 170 168 $this->items = array_slice( $_comments, 0, $comments_per_page ); 171 169 $this->extra_items = array_slice( $_comments, $comments_per_page ); -
trunk/src/wp-includes/class-wp-comment-query.php
r55607 r55749 482 482 $comment_ids = array_map( 'intval', $comment_ids ); 483 483 484 if ( $this->query_vars['update_comment_meta_cache'] ) { 485 wp_lazyload_comment_meta( $comment_ids ); 486 } 487 484 488 if ( 'ids' === $this->query_vars['fields'] ) { 485 489 $this->comments = $comment_ids; … … 487 491 } 488 492 489 _prime_comment_caches( $comment_ids, $this->query_vars['update_comment_meta_cache']);493 _prime_comment_caches( $comment_ids, false ); 490 494 491 495 // Fetch full comment objects from the primed cache. -
trunk/src/wp-includes/class-wp-query.php
r55703 r55749 2814 2814 wp_cache_add( $cache_key, $comment_ids, 'comment-queries' ); 2815 2815 } 2816 _prime_comment_caches( $comment_ids , false);2816 _prime_comment_caches( $comment_ids ); 2817 2817 2818 2818 // Convert to WP_Comment. … … 3373 3373 wp_cache_add( $comment_cache_key, $comment_ids, 'comment-queries' ); 3374 3374 } 3375 _prime_comment_caches( $comment_ids , false);3375 _prime_comment_caches( $comment_ids ); 3376 3376 3377 3377 // Convert to WP_Comment. … … 3488 3488 } 3489 3489 3490 // If comments have been fetched as part of the query, make sure comment meta lazy-loading is set up.3491 if ( ! empty( $this->comments ) ) {3492 wp_queue_comments_for_comment_meta_lazyload( $this->comments );3493 }3494 3495 3490 if ( ! $q['suppress_filters'] ) { 3496 3491 /** -
trunk/src/wp-includes/comment-template.php
r55660 r55749 1441 1441 1442 1442 $comment_args = array( 1443 'orderby' => 'comment_date_gmt', 1444 'order' => 'ASC', 1445 'status' => 'approve', 1446 'post_id' => $post->ID, 1447 'no_found_rows' => false, 1448 'update_comment_meta_cache' => false, // We lazy-load comment meta for performance. 1443 'orderby' => 'comment_date_gmt', 1444 'order' => 'ASC', 1445 'status' => 'approve', 1446 'post_id' => $post->ID, 1447 'no_found_rows' => false, 1449 1448 ); 1450 1449 … … 2380 2379 $parsed_args['reverse_top_level'] = ( 'desc' === get_option( 'comment_order' ) ); 2381 2380 } 2382 2383 wp_queue_comments_for_comment_meta_lazyload( $_comments );2384 2381 2385 2382 if ( empty( $parsed_args['walker'] ) ) { -
trunk/src/wp-includes/comment.php
r55732 r55749 486 486 487 487 /** 488 * Queue comment meta for lazy-loading. 489 * 490 * @since 6.3.0 491 * 492 * @param array $comment_ids List of comment IDs. 493 */ 494 function wp_lazyload_comment_meta( array $comment_ids ) { 495 if ( empty( $comment_ids ) ) { 496 return; 497 } 498 $lazyloader = wp_metadata_lazyloader(); 499 $lazyloader->queue_objects( 'comment', $comment_ids ); 500 } 501 502 /** 488 503 * Updates comment meta field based on comment ID. 489 504 * … … 515 530 * 516 531 * @since 4.5.0 532 * @since 6.3.0 Use wp_lazyload_comment_meta() for lazy-loading of comment meta. 533 * 534 * @see wp_lazyload_comment_meta() 517 535 * 518 536 * @param WP_Comment[] $comments Array of comment objects. … … 529 547 } 530 548 531 if ( $comment_ids ) { 532 $lazyloader = wp_metadata_lazyloader(); 533 $lazyloader->queue_objects( 'comment', $comment_ids ); 534 } 549 wp_lazyload_comment_meta( $comment_ids ); 535 550 } 536 551 … … 3332 3347 * @since 4.4.0 3333 3348 * @since 6.1.0 This function is no longer marked as "private". 3349 * @since 6.3.0 Use wp_lazyload_comment_meta() for lazy-loading of comment meta. 3334 3350 * 3335 3351 * @see update_comment_cache() … … 3346 3362 $fresh_comments = $wpdb->get_results( sprintf( "SELECT $wpdb->comments.* FROM $wpdb->comments WHERE comment_ID IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) ); 3347 3363 3348 update_comment_cache( $fresh_comments, $update_meta_cache ); 3364 update_comment_cache( $fresh_comments, false ); 3365 } 3366 3367 if ( $update_meta_cache ) { 3368 wp_lazyload_comment_meta( $comment_ids ); 3349 3369 } 3350 3370 } -
trunk/tests/phpunit/tests/comment/metaCache.php
r55745 r55749 12 12 * @covers ::update_comment_meta 13 13 */ 14 public function test_update_comment_meta_cache_should_default_to_ true() {14 public function test_update_comment_meta_cache_should_default_to_lazy_loading() { 15 15 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 16 16 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); … … 23 23 clean_comment_cache( $comment_ids ); 24 24 25 $q = new WP_Comment_Query( 25 $num_queries = get_num_queries(); 26 $q = new WP_Comment_Query( 26 27 array( 27 28 'post_ID' => $p, … … 29 30 ); 30 31 32 $this->assertSame( 2, get_num_queries() - $num_queries, 'Querying comments is expected to make two queries' ); 33 31 34 $num_queries = get_num_queries(); 32 35 foreach ( $comment_ids as $cid ) { … … 34 37 } 35 38 36 $this->assertSame( $num_queries, get_num_queries());37 } 38 39 /** 40 * @ticket 1689441 * 42 * @covers :: update_comment_meta43 */ 44 public function test_update_comment_meta_cache_ true() {39 $this->assertSame( 1, get_num_queries() - $num_queries, 'Querying comments is expected to make two queries' ); 40 } 41 42 /** 43 * @ticket 57801 44 * 45 * @covers ::wp_lazyload_comment_meta 46 */ 47 public function test_update_comment_meta_cache_should_default_to_lazy_loading_fields_id() { 45 48 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 46 49 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); … … 53 56 clean_comment_cache( $comment_ids ); 54 57 55 $q = new WP_Comment_Query( 58 $num_queries = get_num_queries(); 59 $q = new WP_Comment_Query( 60 array( 61 'post_ID' => $p, 62 'fields' => 'ids', 63 ) 64 ); 65 66 $this->assertSame( 1, get_num_queries() - $num_queries, 'Querying comments is expected to make two queries' ); 67 68 $num_queries = get_num_queries(); 69 foreach ( $comment_ids as $cid ) { 70 get_comment_meta( $cid, 'foo', 'bar' ); 71 } 72 73 $this->assertSame( 1, get_num_queries() - $num_queries, 'Comment meta is expected to be lazy loaded' ); 74 } 75 76 /** 77 * @ticket 16894 78 * 79 * @covers ::update_comment_meta 80 */ 81 public function test_update_comment_meta_cache_true() { 82 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 83 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); 84 85 foreach ( $comment_ids as $cid ) { 86 update_comment_meta( $cid, 'foo', 'bar' ); 87 } 88 89 // Clear comment cache, just in case. 90 clean_comment_cache( $comment_ids ); 91 92 $num_queries = get_num_queries(); 93 $q = new WP_Comment_Query( 56 94 array( 57 95 'post_ID' => $p, … … 59 97 ) 60 98 ); 99 $this->assertSame( 2, get_num_queries() - $num_queries, 'Comments should be queries and primed in two database queries' ); 61 100 62 101 $num_queries = get_num_queries(); … … 65 104 } 66 105 67 $this->assertSame( $num_queries, get_num_queries() ); 106 $this->assertSame( 1, get_num_queries() - $num_queries, 'Comment meta should be loaded in one database query' ); 107 } 108 109 /** 110 * @ticket 57801 111 * 112 * @covers ::update_comment_meta 113 */ 114 public function test_update_comment_meta_cache_true_multiple() { 115 $posts = self::factory()->post->create_many( 3 ); 116 $all_comment_ids = array(); 117 foreach ( $posts as $p ) { 118 $comment_ids = self::factory()->comment->create_post_comments( $p, 3 ); 119 120 foreach ( $comment_ids as $cid ) { 121 update_comment_meta( $cid, 'foo', 'bar' ); 122 $all_comment_ids[] = $cid; 123 } 124 125 $num_queries = get_num_queries(); 126 $q = new WP_Comment_Query( 127 array( 128 'post_ID' => $p, 129 'update_comment_meta_cache' => true, 130 ) 131 ); 132 $this->assertSame( 1, get_num_queries() - $num_queries, 'Comment query should only add one query' ); 133 } 134 135 $filter = new MockAction(); 136 add_filter( 'update_comment_metadata_cache', array( $filter, 'filter' ), 10, 2 ); 137 $num_queries = get_num_queries(); 138 get_comment_meta( $comment_ids[0], 'foo', 'bar' ); 139 140 $this->assertSame( 1, get_num_queries() - $num_queries, 'Comment meta should be loaded in one database query' ); 141 $args = $filter->get_args(); 142 $first = reset( $args ); 143 $prime_comment_ids = end( $first ); 144 $this->assertSameSets( $prime_comment_ids, $all_comment_ids, 'All comment meta should be loaded all at once' ); 68 145 } 69 146 … … 93 170 } 94 171 95 $this->assertSame( $num_queries + 3, get_num_queries());172 $this->assertSame( 3, get_num_queries() - $num_queries ); 96 173 } 97 174 … … 121 198 $num_queries = get_num_queries(); 122 199 get_comment_meta( $comment_ids[0], 'sauce' ); 123 $this->assertSame( $num_queries + 1, get_num_queries());200 $this->assertSame( 1, get_num_queries() - $num_queries ); 124 201 125 202 // Second and third requests should be in cache. 126 203 get_comment_meta( $comment_ids[1], 'sauce' ); 127 204 get_comment_meta( $comment_ids[2], 'sauce' ); 128 $this->assertSame( $num_queries + 1, get_num_queries());205 $this->assertSame( 1, get_num_queries() - $num_queries ); 129 206 } 130 207 } … … 135 212 * 136 213 * @covers ::get_comment_meta 214 * @covers ::wp_lazyload_comment_meta 137 215 */ 138 216 public function test_comment_meta_should_be_lazy_loaded_in_comment_feed_queries() { … … 183 261 * 184 262 * @covers ::get_comment_meta 263 * @covers ::wp_lazyload_comment_meta 185 264 */ 186 265 public function test_comment_meta_should_be_lazy_loaded_in_single_post_comment_feed_queries() {
Note: See TracChangeset
for help on using the changeset viewer.