Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#64506 new enhancement

wp_dashboard_recent_comments executes an unnecessary SQL query

Reported by: kalessil's profile kalessil Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.9
Component: Comments Keywords: has-patch
Focuses: administration, performance Cc:

Description

The function fetches comments from the DB in a loop that breaks when the target number of comments is reached, or the query returns no results.

If the very first query returns, e.g., just a single comment, this logic causes an unnecessary DB query.

While it's not an issue for smaller instances, for WooCommerce stores with many orders/products, even a few comments, avoiding unnecessary DB queries (expensive in the mentioned setups) improves dashboard performance.

To reproduce, you'll need a testing site with fewer than 25 comments (e.g., just one) and the Query Monitor plugin (to explore DB queries): log in to the admin area, and after you get automatically redirected to the dashboard, note two queries fetching comments (with limit 0, 25, 25, 50).

I'll create a GitHub PR shortly - for reviews and better highlighting the technical side of the issue.

Change History (2)

This ticket was mentioned in PR #10736 on WordPress/wordpress-develop by kalessil.


4 weeks ago
#1

  • Keywords has-patch added

Tune wp_dashboard_recent_comments performance:

  • further reduce the number of count calls (related to history of changes in this functions)
  • harden while-loop condition to avoid SQLs when the last query fetched less that aimed (next query will fetch nothing)

Trac ticket: https://core.trac.wordpress.org/ticket/64506

#2 @SergeyBiryukov
4 weeks ago

  • Component changed from Administration to Comments
  • Focuses administration performance added
Note: See TracTickets for help on using tickets.