[wp-trac] [WordPress Trac] #32366: wp_count_comments() is hardcoded into /wp-admin/menu.php and queries all comments every single page load within the admin area, regardless of if edt_posts is removed from top menu or not
WordPress Trac
noreply at wordpress.org
Tue May 12 23:07:14 UTC 2015
#32366: wp_count_comments() is hardcoded into /wp-admin/menu.php and queries all
comments every single page load within the admin area, regardless of if
edt_posts is removed from top menu or not
-----------------------------------------+-----------------------------
Reporter: justindocanto | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: 4.2.2
Severity: normal | Keywords:
Focuses: administration, performance |
-----------------------------------------+-----------------------------
wp_count_comments() is hardcoded into /wp-admin/menu.php and queries all
comments every single page load within the admin area, regardless of if
edt_posts is removed from top menu or not.
This is reproducible with 0 plugins and any core theme, as long as you
have a large number of comments.
Currently working on a site with 5,000,000+ comments and unless we comment
out the following code in /wp-admin/menu.php, the server gets hammered.
With multiple people in the admin area at the same time, it's even worse,
since it loads on every single page load.
The code: /wp-admin/menu.php - Line 94-97 (4.2.2)
{{{
$awaiting_mod = wp_count_comments();
$awaiting_mod = $awaiting_mod->moderated;
$menu[25] = array( sprintf( __('Comments %s'), "<span class='awaiting-mod
count-$awaiting_mod'><span class='pending-count'>" .
number_format_i18n($awaiting_mod) . "</span></span>" ), 'edit_posts',
'edit-comments.php', '', 'menu-top menu-icon-comments', 'menu-comments',
'dashicons-admin-comments' );
unset($awaiting_mod);
}}}
it's wp_count_comments that causes the large queries, when you have a lot
of comments, but I comment out his entire section so that there isnt any
errors with removing the creation of $awaiting_mod since it's being called
on the next couple lines, before it is unset.
Before I found the source, and saw that it was hard coded, I was hoping
for some sort of hook to disable this entire function and/or a way for the
wp_count_comments() to not be called if the item was removed... but thats
not currently possible.
I'm new to working on core, so i'm not sure on the best way to attack this
issue. I figured it was best to bring up the issue and learn how you guys
tackle the code. Open to coding a solution myself if somebody can point me
in the right direction. Thanks.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32366>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list