[wp-trac] [WordPress Trac] #22040: wp_dashboard_recent_comments queries do not skip comment_approved=spam

WordPress Trac wp-trac at lists.automattic.com
Fri Sep 28 17:56:48 UTC 2012


#22040: wp_dashboard_recent_comments queries do not skip comment_approved=spam
-----------------------------+--------------------------
 Reporter:  _ck_             |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Performance
  Version:                   |   Severity:  normal
 Keywords:                   |
-----------------------------+--------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22040>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list