[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
Thu Feb 28 04:07:57 UTC 2019
#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: (none)
Type: defect (bug) | Status: reopened
Priority: normal | Milestone:
Component: Comments | Version: 4.2
Severity: normal | Resolution:
Keywords: has-patch close | Focuses: administration, performance
-----------------------------+------------------------------------------
Comment (by iCaleb):
> When multiple plugins `add_filter wp_count_comments`, each with their
own logic, possibly making heavy queries, situation becomes significantly
more complex.
This is key to the problem here. I'm looking at a site right now where
there are filters on `wp_count_comments` coming from WooCommerce, WC
Memberships, and Action Scheduler as they need to remove their own comment
types from being returned. Each of these queries becoming significantly
heavier as the site size increases. What's perhaps even worse is that the
site has comments completely disabled, and doesn't even use them in the
traditional post-reply sense.
The filter inside of `wp_count_comments` is simply not sufficient because
it doesn't grant enough context. There are two places in the admin where
comments are counted on every page:
- In the menu (the cause of this ticket):
https://github.com/WordPress/WordPress/blob/6fd8080e7ee7599b36d4528f72a8ced612130b8c
/wp-admin/menu.php#L77
- In the admin bar
https://github.com/WordPress/WordPress/blob/f2d2126d0d8d4c329141bbdbbd3f24a0f44e7d5c
/wp-includes/admin-bar.php#L886
The later can be removed by unhooking it from `admin_bar_menu`. And a
bonus location on the dashboard where you can also remove the
`wp_count_comments()` call by unsetting the "At a Glance" widget.
----
While I would still love a way to unhook the call from menu.php, it might
be worth also taking a step back and see what the underlining issue is
here.
The three plugins I mentioned are all doing the same thing on the
`wp_count_comments` filter. They re-query and remove their custom
comment_type's from the response. So maybe the better answer is an
optional, filter-powered query clause in `get_comment_count()` where
plugins can pass a list of comment_types that need to be ignored? It will
slow the query down, but it's 1000x better than having to query the whole
thing again to remove just one type at a time.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32366#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list