I have a question about the semantics of child_count
in the comment list API endpoint. Sorry for being related to an earlier question but I haven't quite figured it out yet.
My assumption was that child_count
would indicate the amount of total descendants of a comment, regardless of depth. But take this case for example:
$ curl 'https://lemmy.ml/api/v3/comment/list?parent_id=2157873&max_depth=999&limit=999' | jq '.comments[]
| { path: .comment.path, id: .comment.id, content: .comment.content, child_count: .counts.child_count }'
{
"path": "0.2157873",
"id": 2157873,
"content": "Really cool! I'm excited to learn more about you and the project!\n\nWhat's the format? Should we submit questions beforehand, or will you process questions that arrive at the start time? I've never participated in an AMA 😅 ",
"child_count": 9
}
{
"path": "0.2157873.2158260",
"id": 2158260,
"content": "You just post questions as top-level replies to the stickied thread that day, and we'll be online to answer them.",
"child_count": 6
}
{
"path": "0.2157873.2158260.2158286",
"id": 2158286,
"content": "Cool. Thank you for doing this!",
"child_count": 1
}
{
"path": "0.2157873.2158260.2229041",
"id": 2229041,
"content": "Post doesn’t mention, where is the AMA? Here or in a different community?",
"child_count": 3
}
{
"path": "0.2157873.2158260.2158286.2158743",
"id": 2158743,
"content": "No probs!",
"child_count": 0
}
{
"path": "0.2157873.2158260.2229041.2231423",
"id": 2231423,
"content": "As the post mentions, it will be stickied to the top of lemmy.ml ",
"child_count": 2
}
{
"path": "0.2157873.2158260.2229041.2231423.2231737",
"id": 2231737,
"content": "Thanks for the details. May be I’m missing something, but I don’t see that detail in the post. ![](https://programming.dev/pictrs/image/82c90859-9cfb-4c00-80d8-7e96bfd96c1c.jpeg)",
"child_count": 1
}
{
"path": "0.2157873.2158260.2229041.2231423.2231737.2238347",
"id": 2238347,
"content": "Oops my bad, that was something I responded to in a comment.",
"child_count": 0
}
I see that comment 2157873 has a child count of 9, with one direct descendant (2158260). The descendant has a child count of 6. I'd reason that comment 2157873 has 2 direct descendants that aren't visible in the API response yet, because it has one visible descendant having a child count of 6 (i.e. 9 - 1 - 6 = 2). My calculation seems incorrect because (a) I don't see a 'Load more' indicator for this part of the comment thread on https://lemmy.ml/post/2671212, and (b) every comment shown there also seems present in the API response.
Am I understanding the meaning of child_count
correctly?
I've been studying the underlying PostgreSQL content of path and how child_count gets done the last few days...
First off, is this consistent - as there are some questions about deleted comments, removed comments, personal blocking of users who create comments, banned from community person who created comments, etc. Your API with curl doesn't have an auth on it, so personal blocking shouldn't be a factor (not logged in).
max_depth=999 limit=999
I'm not sure how lemmy_server behaves when ranges are out of bounds here. limit on comments is 300 hard-coded in the Rust code AFAIK, and max_depth like around 15.
I think child_count is intended to mean all generations of children, not "direct replies to this comment" count. In your example:
"path": "0.2157873.2158260", "id": 2158260, "content": "You just post questions as top-level replies to the stickied thread that day, and we'll be online to answer them.", "child_count": 6
The child_count looks correct, hand-counting I get 6 that are all originating off of 2158260.
"path": "0.2157873.2158260.2229041.2231423", "id": 2231423, "content": "As the post mentions, it will be stickied to the top of lemmy.ml ", "child_count": 2
Also looks correct, I see a child and a grandchild, totaling 2 comments in the way I understand they intend to count.
"path": "0.2157873", "id": 2157873, "content": "Really cool! I'm excited to learn more about you and the project!\n\nWhat's the format? Should we submit questions beforehand, or will you process questions that arrive at the start time? I've never participated in an AMA 😅 ", "child_count": 9
I would expect 7 given what you show. Are 2 reply comments deleted, removed?
I do KNOW that in version 0.18.4 - the SQL that updates comment_aggregates child_count does NOT look at deleted or removed. It suspect it always counts them as children, even if you as a non-moderator, non-administrator can not fetch them. The fetch policy has changed in 0.18.x releases, it used to be you could indeed load deleted comments and even see their content.
As I said first off, is this consistent? Can we find a 9-count comment tree that has all 9 where there are no delete or remove at play.
I have this post replicated to my own instance where I have direct SQL access: https://BulletinTree.com/comment/1318138
ShowI'm looking at it and I see 2 deleted-by-creator that seem to be direct replies to the first comment in the branch that says 9.
The lemmy-ui I am running is off main, not the 0.18.0 branch, and I just updated it a couple days ago. But it obviously differs in exposing these, and so does my API.
EDIT: I updated my lemmy-ui to main just now again, it had changes, and still showing. Obviously my API is returning the deleted comments for not-logged-in users still... I wonder if that's because I'm running main of lemmy_server and not the 0.18.4 tag branch and they differ in behavior.
Interesting! If there are two deleted comments underneath 2157873, that could indeed explain the two "missing" comments.
I took a look at how the official Lemmy UI uses
child_count
, and it appears to use the number verbatim in its "X more replies" link. So if a comment tree were to include deleted comments, butchild_count
includes the deleted ones, I'd assume the displayed number would be incorrect.Also, it appears that it only displays a load more link if no child comments are currently loaded for that comment and
child_count
is bigger than 0.
Might be applicable here—if you have chosen to not show bot accounts, bot account comments will be removed from the response but the comment count doesn’t account for those comments