wp_dashboard_recent_comments queries do not skip comment_approved=spam
|Reported by:||_ck_||Owned by:|
There is am oversight in wp_dashboard_recent_comments which can cause a large delay in the admin area for large sites that may have a lot of spam (ie. set by akismet)
Ironically the function contains the documentation
"Select all comment types and filter out spam later for better query performance."
This is not the case, in fact it's the opposite. Filtering out the spam later via php and wp filters is far far slower since there is (now) an index on comment_approved.
As it is, it causes dozens of extra queries while it loops through all the comments 50 at a time in mysql when they contain a great deal of spam, and then via php filters the spam out (even for admin).
Since there IS an index on comment_approved that can be used, to fix this you should only show WHERE comment_approved='approved' OR comment_approved='moderated' Or do the reverse with comment_approved!='spam'
Since WP 3.5 has switched to a query class for comments, it should in theory be easy to add the additional WHERE condition for comment_approved.