[wp-trac] [WordPress Trac] #19903: wp_count_comments() and get_comments_count() both do SQL queries

WordPress Trac wp-trac at lists.automattic.com
Fri Jan 27 02:11:27 UTC 2012


#19903: wp_count_comments() and get_comments_count() both do SQL queries
-------------------------+--------------------
 Reporter:  markjaquith  |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  3.4
Component:  Comments     |     Version:  3.3.1
 Severity:  normal       |  Resolution:
 Keywords:               |
-------------------------+--------------------

Old description:

> {{{wp_count_comments()}}} and {{{get_comments_count()}}} are similar
> functions, with a few differences:
>
> * Their results are returned in different formats:
>  * {{{wp_count_comments()}}} returns an array of:
>   * spam
>   * approved
>   * moderated
>   * total_comments
>   * trash
>   * post-trashed
>  * {{{get_comment_count()}}} returns an array of:
>   * spam
>   * approved
>   * awaiting_moderation
>   * total_comments
> * {{{wp_count_comments()}}} caches, but {{{get_comment_count()}}} always
> hits the database.
> * {{{get_comment_count()}}} is used nowhere in WordPress core.
>
> I propose that we add 'trash' and 'post-trashed' reporting to
> {{{get_comment_count()}}}, and then have {{{wp_count_comments()}}}  use
> {{{get_comment_count()}}} instead of doing its own SQL queries.
>
> See #6884 and #19901

New description:

 {{{wp_count_comments()}}} and {{{get_comments_count()}}} are similar
 functions, with a few differences:

 * Their results are returned in different formats:
  * {{{wp_count_comments()}}} returns an object of:
   * spam
   * approved
   * moderated
   * total_comments
   * trash
   * post-trashed
  * {{{get_comment_count()}}} returns an array of:
   * spam
   * approved
   * awaiting_moderation
   * total_comments
 * {{{wp_count_comments()}}} caches, but {{{get_comment_count()}}} always
 hits the database.
 * {{{get_comment_count()}}} is used nowhere in WordPress core.

 I propose that we add 'trash' and 'post-trashed' reporting to
 {{{get_comment_count()}}}, and then have {{{wp_count_comments()}}}  use
 {{{get_comment_count()}}} instead of doing its own SQL queries.

 See #6884 and #19901

--

Comment (by markjaquith):

 Fixing the description to note that wp_count_comments() returns an object.

 > Could the deprecated version become a wrapper for wp_count_comments()?
 We'd simply need to rename the returned array keys.

 Maybe. Unless people are using it to get "hot" data from the database. The
 cached counts might sometimes be wrong.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19903#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list