Make WordPress Core

Opened 4 years ago

Last modified 3 months ago

#19903 closed enhancement

wp_count_comments() and get_comments_count() both do SQL queries — at Initial Version

Reported by: markjaquith Owned by:
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.3.1
Component: Comments Keywords: has-patch
Focuses: performance Cc:


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

Change History (0)

Note: See TracTickets for help on using tickets.