Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#12611 closed defect (bug) (fixed)

Performance hit from update_post_caches

Reported by: prettyboymp's profile prettyboymp Owned by: ryan's profile ryan
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)

update_post_caches.diff (1.2 KB) - added by scribu 15 years ago.
add 'cache_results' option
12611.diff (838 bytes) - added by ryan 15 years ago.
12611.2.diff (810 bytes) - added by ryan 15 years ago.

Download all attachments as: .zip

Change History (13)

#1 @nacin
15 years ago

  • Milestone changed from Unassigned to 3.0

#2 @nacin
15 years ago

  • Owner set to ryan
  • Status changed from new to assigned

#3 @jeffstieler
15 years ago

  • Cc jeff@… added

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.

@scribu
15 years ago

add 'cache_results' option

#4 @scribu
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.

#5 @scribu
15 years ago

Also see #12989.

#6 @scribu
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.

#7 @ryan
15 years ago

Here's something I've been using on wordpress.com (adapted for [14310])

@ryan
15 years ago

#8 @ryan
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.

@ryan
15 years ago

#9 @ryan
15 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Opening to suggest we set cache_results to false, by default, if an external object cache is being used.

#10 @automattor
15 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [14665]) Don't update_post_caches if a persistent object cache is installed. fixes #12611

Note: See TracTickets for help on using tickets.