[wp-trac] [WordPress Trac] #64506: wp_dashboard_recent_comments executes an unnecessary SQL query

WordPress Trac noreply at wordpress.org
Thu Jan 15 08:33:00 UTC 2026


#64506: wp_dashboard_recent_comments executes an unnecessary SQL query
----------------------------+-----------------------------
 Reporter:  kalessil        |      Owner:  (none)
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Administration  |    Version:  6.9
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64506>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list