[wp-trac] [WordPress Trac] #28410: Walking too many nested comments is inefficient and can break sites

WordPress Trac noreply at wordpress.org
Fri May 30 19:54:53 UTC 2014


#28410: Walking too many nested comments is inefficient and can break sites
--------------------------+-----------------------------
 Reporter:  dllh          |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Comments      |    Version:
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 Repro:

 1. Create a post with many thousands of hierarchical comments on a single
 post.
 2. Make sure the option to show nested comments is toggled on.
 3. View the post.

 Expected: The post will display in a timely fashion.

 Actual: The page takes a long time to load (if it loads) and displays way
 too many comments. In extreme cases, the site can just time out.

 This happens because in ```comments_template()``` we select all comments
 and then walk them to establish parent/child relationships. For a very
 popular post, this can be catastrophic to the site, especially if/as more
 and more people pile on to view the site and cause cascading load issues.

 Even in cases in which there's only a handful of top-level comments, if
 there's a lot of nested discussion, the issue manifests.

 Potential fixes include the following:

 1. Load just the first 10 (or however many settings specify) un-parented
 comments for the post and then add some UX that'll fetch child comments in
 via ajax so that we're only ever fetching the comments we need.
 2. Do some kind of recursive logic to fetch only the top 10, then to fetch
 any children of those, and then any children of those, ad infinitum. This
 could get a little ugly and could wind up just shifting the problem by
 trading many smaller queries for one big, bad one.

 I've attached a sample import file with 10k comments on one post and
 random hierarchical assignments. It demonstrates the issue nicely with
 nesting set to 5 levels.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28410>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list