Opened 11 years ago
Last modified 4 days ago
#27736 assigned enhancement
Save one query when inserting a new post
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests close |
Focuses: | administration, performance | Cc: |
Description
The workflow when inserting a new post is the following :
1) wp_insert_post()
sets a few vars (post type, post status, ...), updates $wpdb->posts
, then calls wp_set_post_categories()
2) first thing wp_set_post_categories()
wants to know is $post_type
and $post_status
, for which it performs an SQL query, instead of getting this info from caller function
Same things goes for wp_insert_attachment()
Patch passes extra optional parameters $post_type
and $post_status
to wp_set_post_categories()
, to save one query when adding a post, or a whole bunch when importing a batch.
Attachments (4)
Change History (14)
#2
@
11 years ago
This seems pretty straightforward. We're also now always using braces on all if statements.
#6
@
10 years ago
- Keywords needs-refresh added
The patch does not apply and seems to ignore all of the changes made in 4.0 (extract()
removal, et al)
This ticket was mentioned in PR #8289 on WordPress/wordpress-develop by @pbearne.
4 days ago
#8
- Keywords has-unit-tests added; needs-refresh removed
…st_status, to the
wp_set_post_categories()` function. The intention is to improve performance by avoiding redundant database calls when the post type and status are already known.
Trac ticket:
#9
@
4 days ago
- Keywords close added
- Owner set to pbearne
- Status changed from new to assigned
Hi all
I refreshed the patch and added tests.
But the tests don't show a saving in DB calls.
I support that the new post is still in the object cache, so the saved calls don't now hit the DB
As such, I will close the tick as it won't fix unless someone else can see the DB saving with the patch
fix wp_insert_attachment() as well