-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't prepare the response body for HEAD requests #7970
base: trunk
Are you sure you want to change the base?
Don't prepare the response body for HEAD requests #7970
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this all together, @anton-vlasenko 🙌🏻 I've got a name tweak suggestion for some of the newly added methods to consider.
* | ||
* @param string $method HTTP method to use. | ||
*/ | ||
public function test_get_items_returns_only_fetches_ids_for_head_requests( $method ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function test_get_items_returns_only_fetches_ids_for_head_requests( $method ) { | |
public function test_get_items_returns_only_ids_for_head_requests( $method ) { |
For this and other same-named tests in the updated test classes under this PR, returns_only_fetches
has two verbs, but should only use one for clarity.
Scanning other test classes, "return" is used more extensively than "fetch", so IMHO these new methods should use returns_only_ids
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted, @ironprogrammer! Having two verbs here doesn't make sense. This is likely the result of extensive copy-pasting between different test classes. :)
I'm leaning towards test_get_items_fetches_only_ids_for_head_requests
, because what I meant is that the get_items()
method fetches only the *id*
column from the database for HEAD requests, as opposed to fetching all columns for GET requests.
Fixed in 9c91e45.
* | ||
* @param string $method HTTP method to use. | ||
*/ | ||
public function test_get_items_only_fetches_ids_for_head_requests( $method ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function test_get_items_only_fetches_ids_for_head_requests( $method ) { | |
public function test_get_items_returns_only_ids_for_head_requests( $method ) { |
Suggestion per previous note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | ||
* @param string $method HTTP method to use. | ||
*/ | ||
public function test_get_items_returns_only_fetches_ids_for_head_requests( $method ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function test_get_items_returns_only_fetches_ids_for_head_requests( $method ) { | |
public function test_get_items_returns_only_ids_for_head_requests( $method ) { |
Suggestion per above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | ||
* @param string $method HTTP method to use. | ||
*/ | ||
public function test_get_items_returns_only_fetches_ids_for_head_requests( $method ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function test_get_items_returns_only_fetches_ids_for_head_requests( $method ) { | |
public function test_get_items_returns_only_ids_for_head_requests( $method ) { |
Suggestion per above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | ||
* @param string $method HTTP method to use. | ||
*/ | ||
public function test_get_items_returns_only_fetches_ids_for_head_requests( $method ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function test_get_items_returns_only_fetches_ids_for_head_requests( $method ) { | |
public function test_get_items_returns_only_ids_for_head_requests( $method ) { |
Suggestion per above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context: WordPress#7970 (comment) Props @ironprogrammer.
Fantastic work, @anton-vlasenko! Let me know how I can help to land this in WP 6.8. I think it would improve editors' loading performance. |
Thank you, @Mamaduka.
Thank you for offering your help! |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Yeah I'm planning on landing this this weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to also disable any meta and term cache priming as well, as this results in database queries.
Also if there are changes to be made for taxononmy endpoint, those changes should also be made for post type endpoint. Otherwise this looks like great work.
$is_head_request = $request->is_method( 'HEAD' ); | ||
if ( $is_head_request ) { | ||
// Force the 'fields' argument. For HEAD requests, only post IDs are required to calculate pagination. | ||
$prepared_args['fields'] = 'ids'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we avoid priming comment meta here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we avoid priming comment meta here as well?
Yes, I think we should avoid priming comment meta here.
Fixed in 294584e
8a73466
to
c7eee61
Compare
c7eee61
to
294584e
Compare
9d1f623
to
b80fd51
Compare
Thank you for the review, @spacedmonkey. |
Trac ticket: https://core.trac.wordpress.org/ticket/56481
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.