[wp-trac] [WordPress Trac] #36904: Add caching to comment feed in WP_Query

WordPress Trac noreply at wordpress.org
Thu Dec 7 01:33:27 UTC 2017


#36904: Add caching to comment feed in WP_Query
--------------------------+-----------------------------
 Reporter:  spacedmonkey  |       Owner:
     Type:  enhancement   |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Query         |     Version:  2.2
 Severity:  normal        |  Resolution:
 Keywords:  needs-patch   |     Focuses:  performance
--------------------------+-----------------------------

Comment (by spacedmonkey):

 [https://core.trac.wordpress.org/attachment/ticket/36904/36904.diff
 36904.diff] fixes the above issue.

 Key changes.

 - New param,`do_comment_feed`. When passed, it added the following
 {{{#!php
 ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type =
 'attachment' ) )
 }}}
 to the comment query. This brings it in line current sql. Seems the
 current comment query check to see if the posts / attachments are public
 before, using the comments.
 - Fixed formatting after code standards change.
 - no_found_rows is set to true.

 The results are good.

 On main comment feed, sql query is
 Before
 {{{#!php
 SELECT  wp_comments.* FROM wp_comments JOIN wp_posts ON (
 wp_comments.comment_post_ID = wp_posts.ID ) WHERE ( post_status =
 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) )
 AND comment_approved = '1'  ORDER BY comment_date_gmt DESC LIMIT 10
 }}}
 After
 {{{#!php
 SELECT  wp_comments.comment_ID FROM wp_comments JOIN wp_posts ON
 wp_posts.ID = wp_comments.comment_post_ID WHERE ( comment_approved = '1' )
 AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type =
 'attachment' ) )  ORDER BY wp_comments.comment_date_gmt DESC,
 wp_comments.comment_ID DESC LIMIT 0,10
 }}}

 Single feed queries are
 Before
 {{{#!php
 SELECT wp_comments.* FROM wp_comments  WHERE comment_post_ID = '1' AND
 comment_approved = '1'  ORDER BY comment_date_gmt DESC LIMIT 10
 }}}
 After
 {{{#!php
 SELECT  wp_comments.comment_ID FROM wp_comments  WHERE ( comment_approved
 = '1' ) AND comment_post_ID = 1  ORDER BY wp_comments.comment_date_gmt
 DESC, wp_comments.comment_ID DESC LIMIT 0,10
 }}}

 The two queries are basically the same, apart from ordering and this only
 due to comment query changing ordering.

 Looking good again, I think. Over to you @boonebgorges !

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36904#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list