Skip to content

Commit 294584e

Browse files
Disable priming meta for HEAD requests to improve performance.
1 parent 2e17f2b commit 294584e

File tree

7 files changed

+27
-0
lines changed

7 files changed

+27
-0
lines changed

src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ public function get_items( $request ) {
266266
if ( $is_head_request ) {
267267
// Force the 'fields' argument. For HEAD requests, only post IDs are required to calculate pagination.
268268
$prepared_args['fields'] = 'ids';
269+
// Disable priming comment meta for HEAD requests to improve performance.
270+
$prepared_args['update_comment_meta_cache'] = false;
269271
}
270272

271273
/**

src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,9 @@ static function ( $format ) {
406406
if ( $is_head_request ) {
407407
// Force the 'fields' argument. For HEAD requests, only post IDs are required to calculate pagination.
408408
$args['fields'] = 'ids';
409+
// Disable priming post meta for HEAD requests to improve performance.
410+
$args['update_post_term_cache'] = false;
411+
$args['update_post_meta_cache'] = false;
409412
}
410413

411414
/**

src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ public function get_items( $request ) {
316316
if ( $is_head_request ) {
317317
// Force the 'fields' argument. For HEAD requests, only term IDs are required.
318318
$prepared_args['fields'] = 'ids';
319+
// Disable priming term meta for HEAD requests to improve performance.
320+
$prepared_args['update_term_meta_cache'] = false;
319321
}
320322

321323
/**

tests/phpunit/tests/rest-api/rest-categories-controller.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,11 +1288,15 @@ public function test_get_items_only_fetches_ids_for_head_requests( $method ) {
12881288
if ( $is_head_request ) {
12891289
$this->assertArrayHasKey( 'fields', $query->query_vars, 'The fields parameter is not set in the query vars.' );
12901290
$this->assertSame( 'ids', $query->query_vars['fields'], 'The query must fetch only term IDs.' );
1291+
$this->assertArrayHasKey( 'update_term_meta_cache', $query->query_vars, 'The update_term_meta_cache key is missing in the query vars.' );
1292+
$this->assertFalse( $query->query_vars['update_term_meta_cache'], 'The update_term_meta_cache value should be false for HEAD requests.' );
12911293
} else {
12921294
$this->assertTrue(
12931295
! array_key_exists( 'fields', $query->query_vars ) || 'ids' !== $query->query_vars['fields'],
12941296
'The fields parameter should not be forced to "ids" for non-HEAD requests.'
12951297
);
1298+
$this->assertArrayHasKey( 'update_term_meta_cache', $query->query_vars, 'The update_term_meta_cache key is missing in the query vars.' );
1299+
$this->assertTrue( $query->query_vars['update_term_meta_cache'], 'The update_term_meta_cache value should be true for HEAD requests.' );
12961300
}
12971301

12981302
if ( ! $is_head_request ) {

tests/phpunit/tests/rest-api/rest-comments-controller.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3516,8 +3516,12 @@ public function test_get_items_only_fetches_ids_for_head_requests( $method ) {
35163516
if ( $is_head_request ) {
35173517
$this->assertArrayHasKey( 'fields', $query->query_vars, 'The fields parameter is not set in the query vars.' );
35183518
$this->assertSame( 'ids', $query->query_vars['fields'], 'The query must fetch only post IDs.' );
3519+
$this->assertArrayHasKey( 'update_comment_meta_cache', $query->query_vars, 'The update_comment_meta_cache key is missing in the query vars.' );
3520+
$this->assertFalse( $query->query_vars['update_comment_meta_cache'], 'The update_comment_meta_cache value should be false for HEAD requests.' );
35193521
} else {
35203522
$this->assertTrue( ! array_key_exists( 'fields', $query->query_vars ) || 'ids' !== $query->query_vars['fields'], 'The fields parameter should not be forced to "ids" for non-HEAD requests.' );
3523+
$this->assertArrayHasKey( 'update_comment_meta_cache', $query->query_vars, 'The update_comment_meta_cache key is missing in the query vars.' );
3524+
$this->assertTrue( $query->query_vars['update_comment_meta_cache'], 'The update_comment_meta_cache value should be true for non-HEAD requests.' );
35213525
return;
35223526
}
35233527

tests/phpunit/tests/rest-api/rest-posts-controller.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,9 +1987,17 @@ public function test_get_items_only_fetches_ids_for_head_requests( $method ) {
19871987
$this->assertSame( 'ids', $query->query['fields'], 'The query must fetch only post IDs.' );
19881988
$this->assertArrayHasKey( 'fields', $query->query_vars, 'The fields parameter is not set in the query vars.' );
19891989
$this->assertSame( 'ids', $query->query_vars['fields'], 'The query must fetch only post IDs.' );
1990+
$this->assertArrayHasKey( 'update_post_term_cache', $query->query_vars, 'The "update_post_term_cache" parameter is missing in the query vars.' );
1991+
$this->assertFalse( $query->query_vars['update_post_term_cache'], 'The "update_post_term_cache" parameter must be false for HEAD requests.' );
1992+
$this->assertArrayHasKey( 'update_post_meta_cache', $query->query_vars, 'The "update_post_meta_cache" parameter is missing in the query vars.' );
1993+
$this->assertFalse( $query->query_vars['update_post_meta_cache'], 'The "update_post_meta_cache" parameter must be false for HEAD requests.' );
19901994
} else {
19911995
$this->assertTrue( ! array_key_exists( 'fields', $query->query ) || 'ids' !== $query->query['fields'], 'The fields parameter should not be forced to "ids" for non-HEAD requests.' );
19921996
$this->assertTrue( ! array_key_exists( 'fields', $query->query_vars ) || 'ids' !== $query->query_vars['fields'], 'The fields parameter should not be forced to "ids" for non-HEAD requests.' );
1997+
$this->assertArrayHasKey( 'update_post_term_cache', $query->query_vars, 'The "update_post_term_cache" parameter is missing in the query vars.' );
1998+
$this->assertTrue( $query->query_vars['update_post_term_cache'], 'The "update_post_term_cache" parameter must be true for non-HEAD requests.' );
1999+
$this->assertArrayHasKey( 'update_post_meta_cache', $query->query_vars, 'The "update_post_meta_cache" parameter is missing in the query vars.' );
2000+
$this->assertTrue( $query->query_vars['update_post_meta_cache'], 'The "update_post_meta_cache" parameter must be true for non-HEAD requests.' );
19932001
}
19942002

19952003
if ( ! $is_head_request ) {

tests/phpunit/tests/rest-api/rest-tags-controller.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,11 +1542,15 @@ public function test_get_items_only_fetches_ids_for_head_requests( $method ) {
15421542
if ( $is_head_request ) {
15431543
$this->assertArrayHasKey( 'fields', $query->query_vars, 'The fields parameter is not set in the query vars.' );
15441544
$this->assertSame( 'ids', $query->query_vars['fields'], 'The query must fetch only term IDs.' );
1545+
$this->assertArrayHasKey( 'update_term_meta_cache', $query->query_vars, 'The update_term_meta_cache key is missing in the query vars.' );
1546+
$this->assertFalse( $query->query_vars['update_term_meta_cache'], 'The update_term_meta_cache value should be false for HEAD requests.' );
15451547
} else {
15461548
$this->assertTrue(
15471549
! array_key_exists( 'fields', $query->query_vars ) || 'ids' !== $query->query_vars['fields'],
15481550
'The fields parameter should not be forced to "ids" for non-HEAD requests.'
15491551
);
1552+
$this->assertArrayHasKey( 'update_term_meta_cache', $query->query_vars, 'The update_term_meta_cache key is missing in the query vars.' );
1553+
$this->assertTrue( $query->query_vars['update_term_meta_cache'], 'The update_term_meta_cache value should be true for HEAD requests.' );
15501554
}
15511555

15521556
if ( ! $is_head_request ) {

0 commit comments

Comments
 (0)