1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed User likes counter shows wrong value

Discussion in 'Resolved Bug Reports' started by Pepelac, Mar 26, 2011.

  1. Pepelac

    Pepelac Well-Known Member

    It's a bit strange, but there seems to be some kind of bug in the likes counter.

    I've started to search for bug after one user's message, where he has written, that he has wrong count of likes in his counter and on the Latest Alerts page.

    So, I've written a SQL query, which compare likes counter from the xf_user table with records from the xf_liked_content table.

    Results of this query you can find in attached archive (for 3 forums).

    Query, which I've used:
    u.like_count AS user_like_count,
    COUNT(l.like_id) AS content_like_count,
    SUM(IF(l.content_type = 'post', 1, 0)) AS post_like_count_total,
    SUM(IF(l.content_type = 'post', IF(p.message_state='visible', 1, 0), 0)) AS post_like_count_visible,
    SUM(IF(l.content_type = 'post', IF(p.message_state='moderated', 1, 0), 0)) AS post_like_count_moderated,
    SUM(IF(l.content_type = 'post', IF(p.message_state='deleted', 1, 0), 0)) AS post_like_count_deleted,
    SUM(IF(l.content_type = 'profile_post', 1, 0)) AS profile_post_like_count_total,
    SUM(IF(l.content_type = 'profile_post', IF(pp.message_state='visible', 1, 0), 0)) AS profile_post_like_count_visible,
    SUM(IF(l.content_type = 'profile_post', IF(pp.message_state='moderated', 1, 0), 0)) AS profile_post_like_count_moderated,
    SUM(IF(l.content_type = 'profile_post', IF(pp.message_state='deleted', 1, 0), 0)) AS profile_post_like_count_deleted
    xf_liked_content AS l
    LEFT JOIN xf_user AS u ON u.user_id = l.content_user_id
    LEFT JOIN xf_post AS p ON p.post_id = l.content_id
    LEFT JOIN xf_profile_post AS pp ON pp.profile_post_id = l.content_id
    GROUP BY l.content_user_id
    HAVING content_like_count <> user_like_count
    Fields description:
    • user_id - user's ID
    • user_like_count - likes counter from the table xf_user
    • content_like_count - total likes count for user from the table xf_liked_content
    • post_like_count_total - total likes count for posts
    • post_like_count_visible - likes count for visible posts
    • post_like_count_moderated - likes count for moderated posts
    • post_like_count_deleted - likes count for deleted posts
    • profile_post_like_count_total - total likes count for profile posts
    • profile_post_like_count_visible- likes count for visible profile posts
    • profile_post_like_count_moderated - likes count for moderated profile posts
    • profile_post_like_count_deleted - likes count for deleted profile posts
    And one more thing. It is possible to remove likes two times. Firstly, XF removes likes when you 'softly' delete content by removing it from the public view. Secondly, XF removes likes for the same content when you delete it permanently.

    Attached Files:

    Romchik® and Pavel Safonov like this.
  2. Kier

    Kier XenForo Developer Staff Member

    This issue is now fixed. I suspect it is related to your inconsistent user like counters.
    Pepelac likes this.
  3. Pepelac

    Pepelac Well-Known Member

    Thank you.

    Can I expect some kind of "rebuild script" which will be possible to run from rebuild cache page in ACP and which will rebuild like counters?
  4. Kier

    Kier XenForo Developer Staff Member

    There won't be one for 1.0.1, but we could look at doing one a little further down the road.
  5. Pepelac

    Pepelac Well-Known Member

    Ok, so I'll try to do this by myself...
  6. Shaun Mason

    Shaun Mason Active Member

    I had to do this for both post count and like count...I wrote queries before I bought this PC, so I had them saved on the old one.

    It happened again today, so it is a recurring bug.

Share This Page