[wp-trac] [WordPress Trac] #8071: Refrain from querying all the comments on a post when paged

WordPress Trac noreply at wordpress.org
Tue Sep 22 20:55:26 UTC 2015


#8071: Refrain from querying all the comments on a post when paged
------------------------------------+---------------------------
 Reporter:  markjaquith             |       Owner:  boonebgorges
     Type:  enhancement             |      Status:  assigned
 Priority:  normal                  |   Milestone:  4.4
Component:  Comments                |     Version:  2.7
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:
------------------------------------+---------------------------

Comment (by boonebgorges):

 [attachment:8071.6.diff] takes the spirit of wonderboymusic's patch and
 moves it deeper into the API. By moving some of the threading+pagination
 logic into `WP_Query` rather than `comments_template()`, we open up the
 performance improvements to other developers.

 Notes:

 * In order to maintain some separation of powers in `WP_Comment_Query`, I
 had to stash the SQL clauses in an object property. That's why you see all
 the red/green there.
 * I'm defaulting `no_found_rows` to `true`. This is in keeping with
 current behavior. `SQL_CALC_FOUND_ROWS` can be very expensive, and I don't
 want to wreak havoc with people using `WP_Comment_Query` for weird things.
 * New param `hierarchical` takes three values: `false` (current and
 default - ignores comment children), `'flat'` (returns a flat array that
 includes descendants), `'threaded'` (returns a tree)
 * To support the tree display, I added some `children` infrastructure to
 `WP_Comment` (`add_child()`, `get_child()`, `get_children()`). None of
 this threaded/tree stuff is used in core - we use a walker instead - but
 it seemed to round out the API.
 * I removed the 'found_comments' filter. A filter on the query seems like
 it's enough. (sometimes it's faster to do `SELECT COUNT(*)`, which I
 assume is why you put the filter on the SQL)
 * With this patch, the 'page_comments' setting becomes pretty meaningless
 - we stomp on it whenever we pass a certain threshold. I think it's a good
 idea to stomp on it, but it makes the UI setting "Break comments into
 pages..." fairly awkward. At some point - now or in the future - we should
 remove the checkbox, leaving only the 'comments_per_page' setting.

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


More information about the wp-trac mailing list