WordPress.org

Make WordPress Core

Opened 9 months ago

Last modified 9 months ago

#46243 new defect (bug)

WordPress Comments Core Query

Reported by: Uranbold Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.0.3
Component: Comments Keywords: dev-feedback
Focuses: Cc:
PR Number:

Description

Hello,

Issue: We have over 400K+ posts and I saw this slow query on any WordPress area on each page.

We had 2M+ comments.

Question: This Query is working on all pages on Dashboard or Settings, Plugin section and any sections why does it? It should works on only all Posts list?

Solution: I have noticed that Header Bar has Comments Icon and that has displayed the Pending Comments count. I have tried to disable it via custom Filter for following.

function admin_bar_remove_comments(){
        global $wp_admin_bar;
        $wp_admin_bar->remove_menu('comments');
}
add_action( 'wp_before_admin_bar_render', 'admin_bar_remove_comments' );

Slow Query:

SELECT comment_approved, COUNT( * ) AS total 
FROM wp_comments 
GROUP BY comment_approved

Environment Information:

WP Version 5.0.3 (also tested 4.9.8)
Theme: Twenty Seventeen (other themes)
Plugins: Query Monitor

Thanks.

Change History (2)

#1 @swissspidy
9 months ago

  • Keywords dev-feedback added

Are you using some sort of object cache on your site? Because the comment count would be cached in that case. Plus, with your amount of data you really should think about leveraging an external object cache.

Plus, you can hook into the wp_count_comments filter to prevent that SQL query from running.

I don't see how else we could drastically improve that query in a way that it's worth doing.

#2 @Uranbold
9 months ago

Hello,

I have checked this with Fresh Multisite Network Installation too. But we had still same Query.

Could you please give me more information about the Leveraging an external object cache.

How do i hook this and prevent SQL query from running?

We have manually Removed the comment.php for get_comment_count().

Thanks.

Note: See TracTickets for help on using tickets.