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

WordPress Trac noreply at wordpress.org
Fri Jan 4 17:47:09 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 RogerTheriault):

 I came across this ticket while investigating performance issues relating
 to many database requests from `wp_unique_post_slug()` in situations where
 a published attachment had an unfortunately common title such as '1' and a
 REST request was made that includes the embeds ( e.g. `/wp-
 json/wp/v2/posts/1234567?_embed=true` )

 The patch doesn't seem to reduce those.

 I may have a minor addition to suggest, but could use a sanity check...

 Is the third parameter for `get_sample_permalink()` necessary here? The
 default is `null` yet an empty string is being passed. It causes the
 post's current post_name to be ignored and as a result, the do loop in
 `wp_unique_post_slug()` iterates wastefully - at least for the cases we've
 tested. (In fact, very wastefully in some cases... many uncached queries
 where there are a lot of uploads with the same short title)

 My suggestion would be to change that line to
 `$sample_permalink = get_sample_permalink( $post->ID, $post->post_title
 );`

 If that should go in a separate ticket, I can open one.

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


More information about the wp-trac mailing list