-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
REST API: Introduce batch controller #25096
REST API: Introduce batch controller #25096
Conversation
PHPUnit is now passing. Before merge I'd like to expand Another thing to consider is a way to indicate that permission checks should be called before request validation happens. Right now Core calls permission checks after request validation which complicates things if verifying whether data is valid could wind up exposing sensitive data. |
); | ||
} | ||
|
||
foreach ( $requests as $i => $batch_request ) { |
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.
Nitpick: $batch_request -> $single_request
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.
Good call, fixed in 47edcf6.
* | ||
* @since 9.0.0 | ||
*/ | ||
public function register_routes() { |
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 understand why this code had to be copied and pasted, still I would love to get rid of it (maybe not in this PR). Maybe by updating WP_REST_Posts_Controller::register_routes()
to accept an optional $allow_batch=false
argument? We could also add a filter to register_rest_route
.
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.
Yeah its really not great. My current thinking is we'll just make all posts controllers opt in to batching when we do the Core merge.
/** | ||
* Tests for the batch controller. | ||
*/ | ||
class REST_Batch_Controller_Test extends WP_Test_REST_TestCase { |
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.
It would be good to test if allow_batch
opt-in works - I don't think any test case actually sets it at the moment.
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.
Isn't that covered in test_batch_requires_allow_batch_opt_in
?
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.
It seems like it tests the case where allow_batch
is not set, but I don't see any test that actually sets allow_batch
to true - maybe I'm missing something. Is it because of the core patch / versioning thing? @TimothyBJacobs
I left a few notes, it looks great overall @TimothyBJacobs ! I would still like to address this comment somehow, but it seems beyond the scope of this PR. I think it's pretty close, awesome work! |
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.
We should update @since
annotations to say 9.2.0, but that's a detail. It seems like a great first version. Let's get it in and iterate where needed. Great job @TimothyBJacobs !
E2E test failures seem unrelated to this PR and are similar to failures on recent commits. It seems like TravisCI is having a bad day :-) |
Description
This PR introduces a batch controller at
/__experimental/batch
. It includes support for a validation mode calledrequire-all-validate
that necessitates that each request pass validation before it is dispatched. This functionality requires the latest trunk. For users not on trunk, a simpler version of batching is implemented.For example:
See #24907, Trac#50244.
How has this been tested?
I've done manual testing of the endpoint and added some basic tests to start. I believe tests will be temporarily failing because of the changes required to the REST API server.
Types of changes
New feature
Checklist: