[wp-trac] [WordPress Trac] #16505: WP should cache that a post has no terms

WordPress Trac wp-trac at lists.automattic.com
Wed Feb 9 12:08:17 UTC 2011


#16505: WP should cache that a post has no terms
--------------------------+----------------------------
 Reporter:  nacin         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Future Release
Component:  Taxonomy      |    Version:  3.0
 Severity:  normal        |   Keywords:  needs-patch
--------------------------+----------------------------
 Despite the initial fetch of all terms for all queried objects, any object
 that has no terms in any taxonomy will not be cached. This causes an
 additional query for each of these objects, come the time a template tag
 needs to pull taxonomy data from cache.

 Each additional template tag (I'm referring to has_term() and friends)
 will continue to generate the query on each call. On stock Twenty Ten,
 this can double the number of queries per pageload due to the in_category
 calls in loop.php. It seems get_post_format() is spared, but I didn't dig
 as to why. The difference is is_object_in_term() in in_category() versus
 get_the_terms() in get_post_format().

 While this won't (normally) happen for posts due to the default category,
 this can happen for custom post types pretty easily. (I say 'normally,'
 because that's exactly what I was just tracking down for the past 45
 minutes.)

 The fix here is to get WP, probably in update_object_term_cache(), to
 discern the difference between having not yet fetched terms for an object,
 and having already tried to fetch terms for an object but none existed.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16505>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list