Make WordPress Core

Opened 9 months ago

Last modified 9 months ago

#64506 new enhancement

wp_dashboard_recent_comments executes an unnecessary SQL query

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

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.


9 months 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
9 months ago

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