Make WordPress Core

#66835 new enhancement

Admin menu and admin bar count every comment status just to show the pending number

Reported by: arunjwilson Owned by:
Priority: normal Milestone: Awaiting Review
Component: Comments Version: trunk
Severity: normal Keywords:
Cc: Focuses: performance

Description

The admin menu (wp-admin/menu.php ~line 100) and the front-end admin bar (wp-includes/admin-bar.php ~line 1179) call wp_count_comments() but only use ->moderated.

Since #58368, get_comment_count() runs one get_comments( count => true ) per status (5 statuses). With a persistent object cache those are cached; without one (common on shared hosting) every admin page and every logged-in front-end page runs 5 COUNT queries for one number (plugins that filter comment counts add more). Measured on 7.1.5; same code in trunk.

Suggestion: a pending-only count for these two callers, e.g. get_comments( array( 'status' => 'hold', 'count' => true ) ), or a $statuses argument for get_comment_count(). The wp_count_comments filter can stay.

Related: #58368, #19901, #32366.

Change History (0)

Note: See TracTickets for help on using tickets.