4 ms·
I'm curious as to how they're structuring the data for their comment trees. Does each comment only have one parent? That parent either being another comment or
by aarongough 16y ago
I'm curious as to how they're structuring the data for their comment trees. Does each comment only have one parent? That parent either being another comment or the parent article? Are they using nested sets?
My preferred alternative is to have all comments have 2 separate parent fields. One that always points to the parent article and another that points to the parent comment if it has one, null otherwise.
Structuring the data this way means that you can fetch all the comments for a particular article very quickly and if you wish simply hand that raw data over to the client to be structured using JavaScript, which helps offload some of the work your server would otherwise be doing...
</armchair_development>
- aarongough 16y agoSo I decided to get out of my armchair and have a look at the code. It's a lot to take in and I've never done any work in python but: It looks like they're already doing part of what I proposed above. Each comment is associated directly with a 'link', and after retrieval the tree is sorted on the server-side. Personally I don't see any reason why the tree couldn't be sorted client-side, sorting definitely seems to be one of their time-sinks, especially given that each tree has to be sorted a number of different ways (by controversy, heat, age, score, etc...), and given that the trees tend to change often (with each vote, and with each new comment)
- ketralnis 16y ago> I don't see any reason why the tree couldn't be sorted client-side The sorting isn't the expensive bit, tmk
- aarongough 16y agoI'd be interested to know what percentage of time it takes up for rendering a comment thread in the live system though.