Opened 15 months ago
Last modified 6 months ago
#59354 new defect (bug)
Unnecessary queries performed when updating a post without providing categories or tags
Reported by: | johnbillion | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests |
Focuses: | performance | Cc: |
Description
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 apost_category
element, there's no point in callingwp_set_post_categories()
. - If
$postarr
doesn't contain atags_input
element, there's no point in callingwp_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
- Publish a post with at least one category
- Update the post via:
<?php wp_insert_post( [ 'ID' => $id, 'post_content' => 'Hello, World!', ] );
- Observe that a significant number of unnecessary taxonomy queries are performed
Change History (2)
This ticket was mentioned in PR #6807 on WordPress/wordpress-develop by @LeonidasMilossis.
6 months ago
#1
- Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
#2
@
6 months ago
If
$postarr
doesn't contain atags_input
element, there's no point in callingwp_set_post_tags()
.
We already do that in wp_insert_post()
and indeed there's no extra queries unless we add 'tags_input' => $tag_id,
in the wp_insert_post()
params.
So, that part can probably be removed from the scope of this ticket.
The submitted PR adds a unit test that attests to that.
Trac ticket: https://core.trac.wordpress.org/ticket/59354