Opened 15 years ago
Closed 15 years ago
#12611 closed defect (bug) (fixed)
Performance hit from update_post_caches
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Performance | Keywords: | dev-feedback |
Focuses: | Cc: |
Description
I question the benefit from updating the post cache during the update_post_caches function, specifically where WP_Query->get_posts() calls the update_post_caches with the returned posts. Since a majority of all get_post() calls using posts that were returned from WP_Query->get_posts() will be used within the loop where the global $post would be used instead of the instance in cache.
Normally, this wouldn't be a big deal, except that in performance testing on a site with memcache setup, the cost of the call to update_post_caches is responsible for ~127ms, or 10% - 20% of the rendering time.
Attachments (3)
Change History (13)
#4
@
15 years ago
- Keywords has-patch added
If you use query_posts and filter the returned columns using the 'posts_fields' filter, the resulting post objects will be cached, and could disrupt normal behavior in your theme.
I've run into this problem too. Patch adds a 'cache_results' option to WP_Query.
I also noticed that update_post_caches() uses an unefficient for loop, when a faster foreach could be used.
#6
@
15 years ago
- Keywords has-patch removed
- Resolution set to fixed
- Status changed from assigned to closed
Since [14310], you can control wether update_post_caches() is called or not.
#8
@
15 years ago
It probably makes sense to never call update_post_caches() when using a persistent cache. The idea with the threshold in that patch was avoiding extra cache priming queries for queries with a low number of posts, but it probably doesn't matter much.
This can cause problems under the following conditions:
If you use query_posts and filter the returned columns using the 'posts_fields' filter, the resulting post objects will be cached, and could disrupt normal behavior in your theme.
This caused an issue for me in a theme recently where I was only retrieving post IDs using query_posts, and then in the archive page loop posts' dates were missing and the permalinks were incorrect.
This also had the side effect of an infinite redirect in the admin when trying to edit the affected posts.