WP should cache that a post has no terms
|Reported by:||nacin||Owned by:||nacin|
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.
Change History (6)
comment:3 wonderboymusic — 15 months ago
- Keywords has-patch added; needs-patch removed
- Milestone changed from Future Release to 3.5