[wp-trac] [WordPress Trac] #19372: Don't call wp_count_comments() when we don't need to

WordPress Trac noreply at wordpress.org
Wed Nov 4 22:46:05 UTC 2015


#19372: Don't call wp_count_comments() when we don't need to
----------------------------+-----------------------------
 Reporter:  johnbillion     |       Owner:  wonderboymusic
     Type:  task (blessed)  |      Status:  assigned
 Priority:  normal          |   Milestone:  4.4
Component:  Comments        |     Version:  3.2
 Severity:  minor           |  Resolution:
 Keywords:  has-patch       |     Focuses:  performance
----------------------------+-----------------------------

Comment (by boonebgorges):

 Replying to [comment:20 justindocanto]:
 > Replying to [comment:16 boonebgorges]:
 > > There is already a filter in the function that lets you disable the
 call to `get_comment_count()`.
 https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-
 includes/comment.php?marks=1725-1727#L1694
 >
 > This functionality uses {{{wp_count_comments()}}} not
 {{{get_comment_count()}}}.
 >
 > The query that functionality runs is {{{$count = $wpdb->get_results(
 "SELECT comment_approved, COUNT( * ) AS num_comments FROM
 {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );}}} which
 is a resource intensive query to run on every single page view when you
 have a large amount of comments.

 Please look more carefully at the link I provided. `get_comment_count()`
 is where the SQL query lives. `wp_count_comments()` is a wrapper that
 provides caching, as well as a filter for short-circuiting the call to
 `get_comment_count()`. I concede that it's not a very fine-grained filter,
 but it will allow for workarounds like the one described by @bordoni in
 [comment:18].

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


More information about the wp-trac mailing list