221
submitted 1 year ago by br3d@lemmy.world to c/fediverse@lemmy.world
you are viewing a single comment's thread
view the rest of the comments
[-] athlon@lemm.ee 4 points 1 year ago

Ok, so basically, there is multiple ways one could comment count. The most obvious option is to count the actual number of comments under the post. This might be in practice slow, as you must load all comments under the post. An alternative approach is to have a count variable for post, which is increased or decreased by 1 if post is added/removed. It's way faster to retrieve that variable, instead of getting all comments and counting the number of them. The problem starts if some anomaly happens that is not accounted for, so for example, if I request the same comment to be deleted multiple times. So that counter can be decreased more than once for the same comment. This could be fixed pretty easily:

if comment_to_delete is deleted {
	// Do not do anything
	return
}

post.comment_count -= 1
delete_comment(comment_to_delete)

And yeah, I thought so too, but ever since I stumbled upon this bug, I think the way the comment count is stored is through the counter variable.

[-] baronvonj@lemmy.world 1 points 1 year ago

I had also read that editing a comment increases the comment count on a post.

this post was submitted on 11 Aug 2023
221 points (98.3% liked)

Fediverse

28283 readers
1059 users here now

A community to talk about the Fediverse and all it's related services using ActivityPub (Mastodon, Lemmy, KBin, etc).

If you wanted to get help with moderating your own community then head over to !moderators@lemmy.world!

Rules

Learn more at these websites: Join The Fediverse Wiki, Fediverse.info, Wikipedia Page, The Federation Info (Stats), FediDB (Stats), Sub Rehab (Reddit Migration), Search Lemmy

founded 1 year ago
MODERATORS