[wp-trac] [WordPress Trac] #50244: Add bulk operation support to the Rest API
WordPress Trac
noreply at wordpress.org
Thu Jun 4 06:03:57 UTC 2020
#50244: Add bulk operation support to the Rest API
--------------------------------------+--------------------------------
Reporter: andraganescu | Owner: TimothyBlynJacobs
Type: feature request | Status: assigned
Priority: high | Milestone: 5.5
Component: REST API | Version: 4.4
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses: performance
--------------------------------------+--------------------------------
Comment (by TimothyBlynJacobs):
I've created a PR with a first pass at what this could look like. Things
for thoughts:
1. I don't really love this being in `wp/v2`, it isn't really part of the
`wp` data namespace. I kinda would like it do just be `wp-json/batch`.
2. Should routes have to opt-in to supporting batching? We could have a
`register_rest_route` flag like `allows_batch`. While theoretically any
properly coded route wouldn't have an issue being used in this manner, not
every route is properly coded ( #50239 ).
3. We could also support a `validate_callback` in the
`register_rest_route` on the same level as `callback` and
`permission_callback` that would take a `WP_REST_Request` object and do
validation for it. This would be helpful for cases where validation has to
be done with all the fields together as context, not just individual field
validation. We'd do the parameter validation first, and then call
`validate_callback` on the whole request.
4. I'm thinking about registering the batch controller as part of
`WP_REST_Server` itself like the namespace routes. That way we don't have
to expose the `match_request_to_handler` method.
5. In `pre` validation mode, validation will happen twice. Once when we
check every request for passing validation, and then again in the
individual dispatch. Adjusting this to only happen once makes me nervous,
but there would be a performance benefit to it only happening once.
6. The `maxItems` number is fairly arbitrary, and isn't currently
implemented #48821.
7. I've omitted support for `GET` requests entirely at the moment. The
other requests will have their own permission checks, so it is more
difficult for an unscrupulous person to create a lot of load. But if we
allow `GET` requests this could easily get out of control with no
permission checks, and the permission checks are non-obvious. I think we
should also encourage using linking/embedding over a batch `GET` for the
time being. So I'd like to punt `GET` batching to a later release.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50244#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list