[wp-trac] [WordPress Trac] #37114: Allow short-circuiting `get_post_class` for performance

WordPress Trac noreply at wordpress.org
Thu Aug 11 11:06:50 UTC 2016


#37114: Allow short-circuiting `get_post_class` for performance
-------------------------------+------------------------------------
 Reporter:  bordoni            |       Owner:
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  trunk
 Severity:  normal             |  Resolution:
 Keywords:  has-patch          |     Focuses:  template, performance
-------------------------------+------------------------------------

Comment (by swissspidy):

 Stumbled upon this again.

 On a site with about 30 posts on the front page and `post_class()` being
 used for each, `get_the_terms()` is being called for every post.

 That includes the `post_format` taxonomy, which isn't supported by the
 theme, but still associated with the `post` post type. That means for
 every post there are unneeded SQL queries to get the post format, even
 though the theme doesn't declare support for it and therefore doesn't care
 about post formats.

 I don't think [attachment:37114.patch] is the solution here. If someone
 wants to basically only use half of the `get_post_class()` output, I'd use
 [attachment:37114.0.patch] and add stuff like post type

 ---

 Interestingly, I'm using an external object cache (Memcached) and
 `get_the_terms()` uses `get_object_term_cache()`. However, it only works
 for the `category` taxonomy, not others (getting a `MEMCACHED_NOTSTORED`
 result code). If it would work for all taxonomies, I wouldn't have to care
 about the queries at all. Anyone experienced the same?

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37114#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list