• the dopamine fiend@lemmy.world
    link
    fedilink
    English
    arrow-up
    64
    ·
    1 year ago

    Are you and OP on the same instance? If not, the phantom comment could be from an instance federated with theirs but not yours.

    • athlon@lemm.ee
      link
      fedilink
      English
      arrow-up
      17
      ·
      1 year ago

      I accidentally made a post that has -3 comments.

      This happens because Lemmy does not count the actual number of comments that there are under the post, but instead there is a counter per post. This is not necessarily a bad thing, but it does not seem like the counter is every synced with the actual count of comments.

      • Mr_Buscemi@lemmy.blahaj.zone
        link
        fedilink
        English
        arrow-up
        3
        ·
        1 year ago

        I think I noticed that if a commenter deleted their comment then the total comments would go down by 1. On a post with only one comment that also got deleted, it made it show as -1 comments.

      • PeleSpirit@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        What does counter per post mean?

        Also, I always thought that was because they have to “call home” to get updated and there’s time in between.

        • athlon@lemm.ee
          link
          fedilink
          English
          arrow-up
          2
          arrow-down
          1
          ·
          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.