Skip to content

Commit

Permalink
Update expected database queries in tests
Browse files Browse the repository at this point in the history
The commit updates the expected number of database queries in several PHPUnit tests. The changes reflect improvements made in database query management and caching strategy. As a result, these tests are now expecting fewer queries than before, ensuring that our performance optimizations are correctly implemented and functioning.
  • Loading branch information
spacedmonkey committed Jun 12, 2024
1 parent 657aebb commit ee9e65e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion tests/phpunit/tests/post/nav-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function test_wp_get_nav_menu_items_cache_primes_posts() {
$start_num_queries = get_num_queries();
wp_get_nav_menu_items( $this->menu_id, array( 'nopaging' => false ) );
$queries_made = get_num_queries() - $start_num_queries;
$this->assertSame( 7, $queries_made, 'Only does 7 database queries when running wp_get_nav_menu_items.' );
$this->assertSame( 6, $queries_made, 'Only does 7 database queries when running wp_get_nav_menu_items.' );

$args = $action->get_args();
$this->assertSameSets( $menu_nav_ids, $args[0][1], '_prime_post_caches() was not executed.' );
Expand Down
32 changes: 14 additions & 18 deletions tests/phpunit/tests/post/primePostCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ public function test_prime_post_caches() {
$num_queries = get_num_queries() - $before_num_queries;

/*
* Four expected queries:
* Three expected queries:
* 1: Posts data,
* 2: Post meta data,
* 3: Taxonomy data,
* 4: Term data.
* 2: Taxonomy data,
* 3: Term data.
*/
$this->assertSame( 4, $num_queries, 'Unexpected number of queries.' );
$this->assertSame( 3, $num_queries, 'Unexpected number of queries.' );

$this->assertSame( array(), _get_non_cached_ids( array( $post_id ), 'posts' ), 'Post is not cached.' );

Expand Down Expand Up @@ -95,13 +94,12 @@ public function test_prime_post_caches_with_multiple_posts() {
$num_queries = get_num_queries() - $before_num_queries;

/*
* Four expected queries:
* Three expected queries:
* 1: Posts data,
* 2: Post meta data,
* 3: Taxonomy data,
* 4: Term data.
* 2: Taxonomy data,
* 3: Term data.
*/
$this->assertSame( 4, $num_queries, 'Unexpected number of queries.' );
$this->assertSame( 3, $num_queries, 'Unexpected number of queries.' );

$this->assertSame( array(), _get_non_cached_ids( self::$posts, 'posts' ), 'Posts are not cached.' );
}
Expand Down Expand Up @@ -165,11 +163,10 @@ public function test_prime_post_caches_only_posts_and_meta_cache() {
$num_queries = get_num_queries() - $before_num_queries;

/*
* Two expected queries:
* One expected queries:
* 1: Posts data.
* 2: Post meta data.
*/
$this->assertSame( 2, $num_queries, 'Unexpected number of queries warming cache.' );
$this->assertSame( 1, $num_queries, 'Unexpected number of queries warming cache.' );

$this->assertSame( array(), _get_non_cached_ids( self::$posts, 'posts' ), 'Posts are not cached.' );

Expand Down Expand Up @@ -202,12 +199,11 @@ public function test_prime_post_caches_accounts_for_posts_without_primed_meta_te
$num_queries = get_num_queries() - $before_num_queries;

/*
* Three expected queries:
* 1: Post meta data,
* 2: Taxonomy data,
* 3: Term data.
* Two expected queries:
* 1: Taxonomy data,
* 2: Term data.
*/
$this->assertSame( 3, $num_queries, 'Unexpected number of queries.' );
$this->assertSame( 2, $num_queries, 'Unexpected number of queries.' );
}

/**
Expand Down
9 changes: 4 additions & 5 deletions tests/phpunit/tests/query/cacheResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -1640,13 +1640,12 @@ public function test_get_post_meta_lazy_loads_all_term_meta_data() {
$num_queries = get_num_queries() - $num_queries_start;

/*
* Four expected queries:
* Three expected queries:
* 1: Post IDs
* 2: Post data
* 3: Post meta data.
* 4: Post term data.
* 2: Post meta data.
* 3: Post term data.
*/
$this->assertSame( 4, $num_queries, 'Unexpected number of queries while querying posts.' );
$this->assertSame( 3, $num_queries, 'Unexpected number of queries while querying posts.' );
$this->assertNotEmpty( $query_posts, 'Query posts is empty.' );

$num_queries_start = get_num_queries();
Expand Down

0 comments on commit ee9e65e

Please sign in to comment.