cheeaun / node-hnapi

Unofficial Hacker News API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Comment count is incorrect

burntcookie90 opened this issue · comments

It seems that HN might have changed their markup and now comments are being returned incorrectly. I'm trying to track down the source of the error, but JS isn't my strongest skill...

edit: looks like they're returning only the top level comment count. rather than total count of children.

if you referring to /news and /news2, the comments count is sort of wrong. It's not the real total comments count, but actually the total parent comments count. The official HN API doesn't give the total count so the only way to get it is to cascade down all the comments and child comments, and manually count them.

The cascade is pretty slow so the code now only get the count of the first-level comments (parent) and doesn't traverse down anymore. This is a temporary solution and I haven't find a performant way to get the real total count yet.

On HackerWeb, I handle it by displaying the "fake" count first. When the user loads a story, item/xxx call will give the real count and HackerWeb updates the count on the list of stories as well.

That's how I've handled it as well. I realized that attempting to generate the full comments count would be pretty bad performance. Does hackernews have a location that we can submit bugs or feature requests?

Unfortunately, they're not accepting issues, only pull requests.

Fixed in 50ab03d