[wp-trac] [WordPress Trac] #45605: REST API: Avoid DB queries from generating sample permalink when possible

WordPress Trac noreply at wordpress.org
Sat Jan 5 20:55:39 UTC 2019


#45605: REST API: Avoid DB queries from generating sample permalink when possible
--------------------------+---------------------
 Reporter:  dlh           |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  5.1
Component:  REST API      |     Version:  5.0
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+---------------------

Comment (by TimothyBlynJacobs):

 I think adding something like this to
 `WP_REST_Controller::get_fields_for_response()` makes sense.

 {{{#!php
 if ( ! empty( $request['context'] ) ) {
         foreach ( $fields as $i => $field ) {
                 if ( isset( $schema['properties'][ $field ]['context'] )
 && ! in_array( $request['context'], $schema['properties'][ $field
 ]['context'] ) ) {
                         unset( $fields[ $i ] );
                 }
         }
 }
 }}}

 That would essentially extend the `_fields` performance increases to all
 requests. After the `_fields` performance enhancement, code would've had
 to been updated to be aware that any field may no longer be in the
 response when filtering  on `rest_prepare_post`. If the code hadn't been
 updated, it would be more likely to experience an issue with that change.
 Thoughts @kadamwhite @danielbachhuber?

 If that is deemed too risky, I think checking the `context` of the request
 manually is fine in this scenario.

 > Is the third parameter for get_sample_permalink() necessary here?...

 This was introduced here:
 https://github.com/WordPress/gutenberg/commit/3d93ac6a2f60fa98a599196785f25a68b9997c12

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45605#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list