-
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
Try setting targetHints automatically. #7139
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. |
@TimothyBJacobs: How's this going? It's marked as a backport for 6.7. Beta 1 is 4 weeks and I'll sync packages in just over 2 weeks. |
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. |
Refreshed with the latest changes from GB. I'll leave it open a few days for feedback. |
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.
This looks good to me based on a read through of the code.
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.
WordPress/gutenberg#65280 needs to be fixed here as well!
WordPress/gutenberg#65280 is required prior to merge.
dd7a4f2
to
a2ffb29
Compare
Merged in r59032. |
@TimothyBJacobs @swissspidy I would like to validate something about this change. The change impacts performance depending on the number of users, posts, and how you hit the users endpoint. When Depending on the number of Questions:
One alternative to work around this is the following. Do you think it's the most appropriate way? /**
* Add targetHints to the self-links in the user response to prevent COUNT slow queries.
*
* @see get_target_hints_for_link core method in WordPress version 6.7
*/
add_filter( 'rest_prepare_user', function( $response, $user, $request ) {
$links = $response->get_links();
if ( empty( $links ) ) {
return $response;
}
$response->remove_link('self');
foreach( $links as $rel => $set ) {
if ( 'self' !== $rel ) {
continue;
}
foreach( $set as $link ) {
if ( ! isset( $link['href'] ) ) {
continue;
}
$response->add_link(
$rel,
$link['href'],
array_merge(
$link['attributes'] ?? [],
[
'targetHints' => [
'allow' => [],
]
]
)
);
}
}
return $response;
}, 10, 3 ); I'm looking forward to hearing your thoughts on this. |
Could you perhaps open a Trac ticket to increase visibility of this? Would you say that caching |
Actually, looks like https://core.trac.wordpress.org/ticket/46249 seems to basically have covered this case, but was pointed to https://core.trac.wordpress.org/ticket/39242 as well.. So yeah, maybe let's focus on the caching? |
This needs to be refactored to be less ugly, and handle errors from
WP_REST_Request::from_url
. But this is my thinking on how we could automatically add a targetHint.Trac ticket: https://core.trac.wordpress.org/ticket/61739
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.