Topic: (API question) /comment/index.json returns varying number of comments when filtered by post_id

Posted under e621 Tools and Applications

Hello, still working on my e621 app. I've noticed that the number of comments returned from the /comment/index.json endpoint varies depending on the specific page and post ID.

As a specific example, for post #1039976:

~> curl "https://e621.net/comment/index.json?post_id=1039976&page=1" | jq length
23
~> curl "https://e621.net/comment/index.json?post_id=1039976&page=2" | jq length
6

Adding &status=any doesn't change the output, and these two pages contain all of the comments on the post anyway. Removing the post_id parameter returns 25 comments consistently (although for all posts).

It's not a major problem and I can code around it, but I'm just wondering why it's not consistently returning 25 comments like how /post/index.json consistently returns limit=75 posts until the last page.

I've been using the number of returned objects to check if there are potentially more pages to load, which saves a network request when the last page has less elements than the page size. (e.g. 30 posts when limit=75). Which is every search that isn't a multiple of the limit (almost all of them).

Updated

I believe that is because of hidden comments.
Basic psuedo code for how it works behind the scenes

comments = query("select stuff from e621.comments where post_id = %", 1049976)
for comment in comments:
    if comment.status == hidden and not admin:
        delete comment

return comments as json

So, judging by the fact you have 23 comments in the first page, that would mean there are 2 comments that are hidden.
Since the database doesn't know if the user is admin or not since that is handled in code, the database doesn't know how many results to actually return. BUT THATS JUST A THEORY, a game code theory.

The best way to go about this is to query the first 25 comments, and if the user continues to scroll down, query the next page. If the list is empty, assume thats the end of the list.

Updated by anonymous

Chaser said:
The best way to go about this is to query the first 25 comments, and if the user continues to scroll down, query the next page. If the list is empty, assume thats the end of the list.

That's what I was doing initially, but ended up wanting a pagination data structure that could handle loading pages of things out of order, so I made the simplifying assumption that every page except the last has the same size.

Chaser said:
I believe that is because of hidden comments.

Can posts be hidden too? I might be truncating search results early.

Updated by anonymous

perlatus said:
That's what I was doing initially, but ended up wanting a pagination data structure that could handle loading pages of things out of order, so I made the simplifying assumption that every page except the last has the same size.

Can posts be hidden too? I might be truncating search results early.

OH! OH! I THINK I FOUND WHAT YOU WANT! :D
https://e621.net/comment/index.json?post_id=1039976&status=active
status=any would show both deleted and active posts, which the deleted ones would be removed from the 25 results.
status=active will only show the active ones, which since anyone can see active ones, none would be trunicated!

Updated by anonymous

Chaser said:
OH! OH! I THINK I FOUND WHAT YOU WANT! :D

Awesome, thanks! Just tried it out and it works. :3

Updated by anonymous

  • 1