[wp-trac] [WordPress Trac] #37696: WP_Comment_Query loses sql_clauses with Object Cache

WordPress Trac noreply at wordpress.org
Wed Sep 7 15:07:49 UTC 2016


#37696: WP_Comment_Query loses sql_clauses with Object Cache
-------------------------------------------------+-------------------------
 Reporter:  Rarst                                |       Owner:
     Type:  defect (bug)                         |  boonebgorges
 Priority:  normal                               |      Status:  reopened
Component:  Comments                             |   Milestone:  4.7
 Severity:  normal                               |     Version:  4.6
 Keywords:  has-patch needs-testing dev-         |  Resolution:
  feedback                                       |     Focuses:
-------------------------------------------------+-------------------------
Changes (by boonebgorges):

 * keywords:  needs-patch => has-patch needs-testing dev-feedback


Comment:

 The problem reported in #37966 is fixed by [attachment:37696.2.diff].
 Here's the logic, which I hope is clear enough to get a review :)

 - To minimize SQL queries, comment trees are fetched one level at a time.
 So if A and B are top-level comments, with children A1, A2, B1, a query
 that fetches A and B will do two queries. The first will grab A and B
 (`parent=0`) and the second will fetch A1, A2, B1 (`parent IN (A,B)`).
 That's what `fill_descendants()` is for.
 - The descendant query should be similar to the parent query. For example,
 if you `get_comments( 'exclude=1,2,3' )`, you expect 1, 2, and 3 to be
 excluded from top-level comments as well as descendants. But the
 descendant query cannot match exactly, because it needs to override the
 `parent__in` parameter; and `parent__in` should override other hierarchy-
 related parameters passed to `WP_Comment_Query`.
 - Prior to [38497], the descendant query was being built by parsing and
 modifying the SQL string for the parent query. This broke, because the SQL
 string is not available in all cases.
 - [38497] changed the strategy so that the descendant query calls
 `get_comments()` instead. The parameters passed to `get_comments()` are
 those passed to `WP_Comment_Query`, with some necessary modifications to
 ensure that we're fetching only the hierarchy level we intend to be
 fetching.
 - What was missed in [38497], and what was reported in #37966, is that the
 'offset' and 'number' parameters are not being reset for the descendant
 query. As such, if you passed `offset=1&number=1` to `WP_Comment_Query`,
 the descendant query would *also* only fetch a single comment, with an
 offset of 1. This is incorrect: the descendant query should always have an
 offset of 0 and no limits on the number of results returned. That's what
 [attachment:37696.2.diff] adds.

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


More information about the wp-trac mailing list