-
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @jonnynews. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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. |
I think we have a BC issue with the single item route. Right now, if I use the I think we might want to move the |
Thank you for the review, @TimothyBJacobs.
It could theoretically happen, but I’m not aware of any such cases. That said, I also agree that GET and HEAD requests should behave similarly, with the exception that HEAD requests don’t include a response body. I’m working on a fix. |
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.
There are 42 files in the endpoints directory. Some of these are sub classes. But there are other endpoints that are not sub classes of the files edited in this PR. Is this applied all the endpoints that need this change?
@jonnynews No, it hasn’t been applied to all the classes that need editing, as this PR focuses only on the most commonly used REST controllers. |
In core, we normally do these things one commit. |
Some controllers might benefit from this work.
To clear, as I am asking, I believe it just a simply copy and paste for most of these endpoints, but correct me if I am wrong. |
Yes, I believe it is. PHPUnit tests would need to be added as well (which can also be partially copy-pasted). I'll work on this tomorrow. Thank you for the review. |
c1dc6e3
to
c9c4d20
Compare
…hod to preserve BC.
c9c4d20
to
8bf96cf
Compare
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.