[wp-trac] [WordPress Trac] #59354: Unnecessary queries performed when updating a post without providing categories or tags

WordPress Trac noreply at wordpress.org
Thu Sep 14 22:43:53 UTC 2023


#59354: Unnecessary queries performed when updating a post without providing
categories or tags
-------------------------------+------------------------------------------
 Reporter:  johnbillion        |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:
 Severity:  normal             |   Keywords:  needs-patch needs-unit-tests
  Focuses:  performance        |
-------------------------------+------------------------------------------
 Given an existing post with at least some categories or tags present,
 updating the post via `wp_update_post()` (which calls `wp_insert_post()`)
 with data that does not include categories or tags, many unnecessary
 taxonomy-related database queries are performed. This slows down the
 saving significantly.

 * If `$postarr` doesn't contain a `post_category` element, there's no
 point in calling `wp_set_post_categories()`.
 * If `$postarr` doesn't contain a `tags_input` element, there's no point
 in calling `wp_set_post_tags()`

 == Todo ==

 * Need tests to verify the above is correct
 * Need a list of queries that are performed before and after the change

 == To reproduce ==

 1. Publish a post with at least one category
 2. Update the post via:
 {{{#!php
 <?php
 wp_insert_post( [
   'ID' => $id,
   'post_content' => 'Hello, World!',
 ] );
 }}}
 3. Observe that a significant number of unnecessary taxonomy queries are
 performed

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59354>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list