Changeset 55671
- Timestamp:
- 04/21/2023 09:22:04 AM (22 months ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-term-query.php
r55526 r55671 866 866 if ( $args['update_term_meta_cache'] ) { 867 867 $term_ids = wp_list_pluck( $term_objects, 'term_id' ); 868 update_termmeta_cache( $term_ids );868 wp_lazyload_term_meta( $term_ids ); 869 869 } 870 870 -
trunk/src/wp-includes/post.php
r55642 r55671 7693 7693 } 7694 7694 7695 if ( $term_ids ) { 7696 $lazyloader = wp_metadata_lazyloader(); 7697 $lazyloader->queue_objects( 'term', $term_ids ); 7698 } 7695 wp_lazyload_term_meta( $term_ids ); 7699 7696 } 7700 7697 -
trunk/src/wp-includes/taxonomy.php
r55526 r55671 1427 1427 } 1428 1428 1429 1430 /** 1431 * Queue term meta for lazy-loading. 1432 * 1433 * @since 6.3.0 1434 * 1435 * @param array $term_ids List of term IDs. 1436 */ 1437 function wp_lazyload_term_meta( array $term_ids ) { 1438 if ( empty( $term_ids ) ) { 1439 return; 1440 } 1441 $lazyloader = wp_metadata_lazyloader(); 1442 $lazyloader->queue_objects( 'term', $term_ids ); 1443 } 1444 1429 1445 /** 1430 1446 * Gets all meta data, including meta IDs, for the given term ID. … … 4004 4020 * @since 4.6.0 4005 4021 * @since 6.1.0 This function is no longer marked as "private". 4022 * @since 6.3.0 Use wp_lazyload_term_meta() for lazy-loading of term meta. 4006 4023 * 4007 4024 * @global wpdb $wpdb WordPress database abstraction object. … … 4018 4035 4019 4036 update_term_cache( $fresh_terms ); 4020 4021 if ( $update_meta_cache ) { 4022 update_termmeta_cache( $non_cached_ids );4023 }4037 } 4038 4039 if ( $update_meta_cache ) { 4040 wp_lazyload_term_meta( $term_ids ); 4024 4041 } 4025 4042 } -
trunk/tests/phpunit/includes/abstract-testcase.php
r55657 r55671 196 196 wp_set_current_user( 0 ); 197 197 198 $lazyloader = wp_metadata_lazyloader(); 199 $lazyloader->reset_queue( 'term' ); 200 $lazyloader->reset_queue( 'comment' ); 198 $this->reset_lazyload_queue(); 201 199 } 202 200 … … 275 273 } 276 274 275 } 276 277 /** 278 * Reset the lazy load meta queue. 279 */ 280 protected function reset_lazyload_queue() { 281 $lazyloader = wp_metadata_lazyloader(); 282 $lazyloader->reset_queue( 'term' ); 283 $lazyloader->reset_queue( 'comment' ); 277 284 } 278 285 -
trunk/tests/phpunit/tests/post/nav-menu.php
r55591 r55671 305 305 306 306 update_menu_item_cache( $query_result ); 307 get_term_meta( $term_id ); 307 308 308 309 $args = $action->get_args(); … … 384 385 $start_num_queries = get_num_queries(); 385 386 wp_get_nav_menu_items( $this->menu_id ); 387 get_term_meta( $term_ids[0] ); 386 388 $queries_made = get_num_queries() - $start_num_queries; 387 389 $this->assertSame( 6, $queries_made, 'Only does 6 database queries when running wp_get_nav_menu_items.' ); 388 390 389 $args = $action_terms->get_args(); 390 $last = end( $args ); 391 $this->assertSameSets( $term_ids, $last[1], '_prime_term_caches() was not executed.' ); 391 $args = $action_terms->get_args(); 392 $first = reset( $args ); 393 $term_ids[] = $this->menu_id; 394 $this->assertSameSets( $term_ids, $first[1], '_prime_term_caches() was not executed.' ); 392 395 393 396 $args = $action_posts->get_args(); -
trunk/tests/phpunit/tests/query/lazyLoadTermMeta.php
r55608 r55671 46 46 */ 47 47 public function test_wp_queue_posts_for_term_meta_lazyload() { 48 $this->reset_lazyload_queue(); 48 49 $filter = new MockAction(); 49 50 add_filter( 'update_term_metadata_cache', array( $filter, 'filter' ), 10, 2 ); -
trunk/tests/phpunit/tests/term/getTerms.php
r54402 r55671 2757 2757 * @ticket 10142 2758 2758 */ 2759 public function test_termmeta_cache_should_be_ primed_by_default() {2759 public function test_termmeta_cache_should_be_lazy_loaded_by_default() { 2760 2760 global $wpdb; 2761 2761 … … 2780 2780 } 2781 2781 2782 $this->assertSame( $num_queries , $wpdb->num_queries );2782 $this->assertSame( $num_queries + 1, $wpdb->num_queries ); 2783 2783 } 2784 2784 -
trunk/tests/phpunit/tests/term/meta.php
r51568 r55671 117 117 global $wpdb; 118 118 119 // Clear any previous term IDs from the queue.120 wp_metadata_lazyloader()->reset_queue( 'term' );121 122 119 $p = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 123 120 … … 200 197 add_term_meta( $t, 'foo', 'bar' ); 201 198 } 202 199 $this->reset_lazyload_queue(); 203 200 $q = new WP_Query( 204 201 array( -
trunk/tests/phpunit/tests/term/query.php
r55083 r55671 45 45 46 46 $this->assertSameSets( array( $term_2 ), $q->terms ); 47 } 48 49 /** 50 * @ticket 57645 51 */ 52 public function test_lazy_load_term_meta() { 53 $filter = new MockAction(); 54 add_filter( 'update_term_metadata_cache', array( $filter, 'filter' ), 10, 2 ); 55 register_taxonomy( 'wptests_tax_1', 'post' ); 56 register_taxonomy( 'wptests_tax_2', 'post' ); 57 58 $term_1 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_1' ) ); 59 $term_2 = self::factory()->term->create( array( 'taxonomy' => 'wptests_tax_2' ) ); 60 61 $q = new WP_Term_Query( 62 array( 63 'taxonomy' => 'wptests_tax_1', 64 'fields' => 'ids', 65 'hide_empty' => false, 66 ) 67 ); 68 69 $this->assertSameSets( array( $term_1 ), $q->terms ); 70 71 $q = new WP_Term_Query( 72 array( 73 'taxonomy' => 'wptests_tax_2', 74 'fields' => 'ids', 75 'hide_empty' => false, 76 ) 77 ); 78 79 $this->assertSameSets( array( $term_2 ), $q->terms ); 80 81 get_term_meta( $term_1 ); 82 83 $args = $filter->get_args(); 84 $first = reset( $args ); 85 $term_ids = end( $first ); 86 $this->assertSameSets( $term_ids, array( $term_1, $term_2 ) ); 47 87 } 48 88 -
trunk/tests/phpunit/tests/term/wpGetObjectTerms.php
r53942 r55671 616 616 * @ticket 10142 617 617 */ 618 public function test_termmeta_cache_should_be_ primed_by_default() {618 public function test_termmeta_cache_should_be_lazy_loaded_by_default() { 619 619 global $wpdb; 620 620 … … 636 636 } 637 637 638 $this->assertSame( $num_queries , $wpdb->num_queries );638 $this->assertSame( $num_queries + 1, $wpdb->num_queries ); 639 639 } 640 640 … … 701 701 } 702 702 703 $this->assertSame( $num_queries , $wpdb->num_queries );703 $this->assertSame( $num_queries + 1, $wpdb->num_queries ); 704 704 } 705 705 … … 734 734 } 735 735 736 $this->assertSame( $num_queries , $wpdb->num_queries );736 $this->assertSame( $num_queries + 1, $wpdb->num_queries ); 737 737 } 738 738
Note: See TracChangeset
for help on using the changeset viewer.