[wp-trac] [WordPress Trac] #50244: Add bulk operation support to the Rest API
WordPress Trac
noreply at wordpress.org
Wed Jun 10 14:04:32 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 zieladam):
@TimothyBlynJacobs I read through that PR and it looks pretty good to me.
Some thoughts:
> 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 ).
I think it should be opt-in - as we discussed earlier, there are important
routes that do not support pre-validation at the moment and sending batch
requests with `validation=pre` will not work as expected. With opt-in
approach, the batch processing endpoint could be merged first and then
more and more routes would opt-in to batch processing as time passes.
> 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.
Great idea
> 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.
One idea would be to re-validate in the individual dispatch by default,
but expose an option to skip this part and only rely on the bulk
validation. The only think that could go wrong there is something
unexpected happening between the batch validation and the handler
invocation, e.g. requesting a batch of two requests, both trying to insert
a row with the same value that's subject to an UNIQUE constraint - I think
core should protect developers from doing that, but offer an option to opt
out of this protection when more performance is required.
> I've omitted support for GET requests entirely at the moment.
Sounds good and makes sense
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50244#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list