3 ms·
That's the method that Disqus used as well.[1] Later on they used a materialized path solution [2], but I remained impressed that the recursive query worked so
by Gracana 12y ago
That's the method that Disqus used as well.[1] Later on they used a materialized path solution [2], but I remained impressed that the recursive query worked so well at their scale, enough so that I used the same method in a personal project that had a hierarchical comment system. Happily, it wasn't much of a hack to do this in Django... the raw query support is quite good; you don't have to sacrifice the ORM to do something like this.
[1] http://cramer.io/2010/05/30/scaling-threaded-comments-on-django-at-disqus/ http://cramer.io/2010/05/30/scaling-threaded-comments-on-dja...
[2] http://cramer.io/2012/04/08/using-arrays-as-materialized-paths-in-postgres/ http://cramer.io/2012/04/08/using-arrays-as-materialized-pat...
- pjungwir 12y agoTo toot my own horn, I wrote a blog post that takes their approach and extends it to sort sibling comments by upvotes, like on HN or Reddit: http://illuminatedcomputing.com/posts/2014/09/postgres-cte-for-threaded-comments/ http://illuminatedcomputing.com/posts/2014/09/postgres-cte-f... It's trickier than you might expect!
- Gracana 12y agoOh awesome, my solution to that is pretty similar. I also added a couple window functions in the final SELECT statement to get each comment's sibling count and position, which my application code uses to do pagination. It's definitely very puzzle-y stuff. Time consuming, but fun when you get a nice solution!