Skip to content
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

Open
wants to merge 13 commits into
base: trunk
Choose a base branch
from

Conversation

anton-vlasenko
Copy link

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.

Copy link

github-actions bot commented Dec 7, 2024

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link

@ironprogrammer ironprogrammer left a 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 ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Copy link
Author

@anton-vlasenko anton-vlasenko Dec 9, 2024

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 ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Author

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 ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Author

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 ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Author

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 ) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mamaduka
Copy link
Member

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.

@anton-vlasenko
Copy link
Author

Fantastic work, @anton-vlasenko!

Thank you, @Mamaduka.

Let me know how I can help to land this in WP 6.8. I think it would improve editors' loading performance.

Thank you for offering your help!
A code review and/or testing report could help with landing this in WordPress 6.8.
This ticket is likely on @TimothyBJacobs's radar, so hopefully, he'll be able to approve and commit it when he has the time, provided there’s no additional feedback from the code review.

@WordPress WordPress deleted a comment from github-actions bot Dec 12, 2024
@desrosj desrosj added the props-bot Adding this label triggers the Props Bot workflow for a PR. label Dec 12, 2024
Copy link

github-actions bot commented Dec 12, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props antonvlasenko, ironprogrammer, swissspidy, spacedmonkey, mamaduka, timothyblynjacobs.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Dec 12, 2024
@TimothyBJacobs
Copy link
Member

Yeah I'm planning on landing this this weekend.

Copy link
Member

@spacedmonkey spacedmonkey left a 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';
Copy link
Member

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?

Copy link
Author

@anton-vlasenko anton-vlasenko Dec 14, 2024

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

@anton-vlasenko anton-vlasenko force-pushed the add/short-circuit-head-requests branch from 8a73466 to c7eee61 Compare December 14, 2024 00:54
@anton-vlasenko anton-vlasenko force-pushed the add/short-circuit-head-requests branch from c7eee61 to 294584e Compare December 14, 2024 00:58
@anton-vlasenko anton-vlasenko force-pushed the add/short-circuit-head-requests branch from 9d1f623 to b80fd51 Compare December 14, 2024 01:51
@anton-vlasenko
Copy link
Author

anton-vlasenko commented Dec 14, 2024

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.

Thank you for the review, @spacedmonkey.
Well spotted.
I've fixed these issues in 294584e and b80fd51.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants