[wp-trac] [WordPress Trac] #45605: REST API: Avoid DB queries from generating sample permalink when possible
WordPress Trac
noreply at wordpress.org
Wed Dec 12 18:58:35 UTC 2018
#45605: REST API: Avoid DB queries from generating sample permalink when possible
--------------------------+-----------------------------
Reporter: dlh | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 5.0
Severity: normal | Keywords: has-patch
Focuses: |
--------------------------+-----------------------------
The results of `get_sample_permalink()` were added to the REST API as part
of #45017. Although the `permalink_template` and `generated_slug` fields
are used only in the `edit` context, the sample permalink is always
generated, which leads to at least one direct database request via
`wp_unique_post_slug()` for each post.
The attached patch would add a check for whether the `permalink_template`
or `generated_slug` fields have been requested before generating the
sample permalink.
However, the attached patch is still not great because
`permalink_template` and `generated_slug` will be considered requested
fields by default.
One potential workaround for this default behavior would be to
deliberately check the request `context` as well as the requested fields
before generating the permalink.
However, that seems duplicative of the work that
`\WP_REST_Controller::filter_response_by_context()` is meant to do, so I'm
not sure it would be the best approach.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45605>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list