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

Fixed Incorrect Comments Count

Discussion in 'Media Gallery Resolved Bugs' started by batpool52!, Feb 14, 2015.

  1. batpool52!

    batpool52! Well-Known Member

  2. Chris D

    Chris D XenForo Developer Staff Member

    I have just tested this locally in a variety of combinations and here at XF.com:
    • Ratings without a comment do not increase the comment count
    • Ratings with a comment do increase it
    • Soft/hard deleting a comment does decrease the count
    • Restoring a soft deleeted comment does increase the comment count
    • Approving / unapproving a comment increases/decreases the count as expected
    Do you have any custom code running that may affect the Gallery?
  3. batpool52!

    batpool52! Well-Known Member

    I do, but even after disabling it there seems to be no change. Rebuking doesn't fix the counter as well (with all the add-ons disabled).
  4. Chris D

    Chris D XenForo Developer Staff Member

    Any sort of caching mechanisms?
  5. batpool52!

    batpool52! Well-Known Member

    Just file caching. Disabling didn't make any changes.
  6. Chris D

    Chris D XenForo Developer Staff Member

    Can it be reproduced reliably at your site?

    e.g. if you rate another media item without a comment does it increase the comment count?

    Really while we can't reproduce this there's not a whole lot we can do so I'll move this to support for now.
  7. batpool52!

    batpool52! Well-Known Member

    It doesn't seem to occur on any other media, only this one https://www.rt-networks.com/media/because-im-batman.3/ I ran this
    SELECT * FROM xengallery_comment WHERE content_id = 3
    query in command line and got only one row back, but while rebuilding the comments count it sets it to 2 + the actual number of comments
  8. Chris D

    Chris D XenForo Developer Staff Member

    I don't think it has any relevance here, but bear in mind the correct query would be:

    SELECT * FROM xengallery_comment WHERE content_id = 3 AND content_type = 'media'
    The code for the rebuild process really isn't very complicated.

    It goes through batches of media items, it counts the number of comments (it only counts comments that match the media id, content type is media and are visible), then regardless of whether it has changed or not, it sets the comment_count field in the xengallery_media table to that count using the Media DataWriter.

    If running this query:

    SELECT COUNT(*) FROM xengallery_comment WHERE content_id = 3 AND content_type = 'media'
    Returns the correct count (e.g. 1 based on what you said above) then there's nothing in the code that would set it to anything different.

    Out of interest, what does this query return?

    SELECT comment_count FROM xengallery_media WHERE media_id = 3
  9. batpool52!

    batpool52! Well-Known Member

    Result is 1, the same result as my smaller query.

    Returns 3 o_O

    Can I just safely update the comment_count to real value? Or there are other places where it needs to be updated?
  10. Chris D

    Chris D XenForo Developer Staff Member

    Well I did expect it to be 3 as that was what was being displayed; but I just wanted to make sure the template was calling that value rather than something else.

    You can update it to the real value, the count in the media table is a cache of the number of comments, though ideally you want to try and work out why it's miscounting. I'm still thinking some code edits or add-ons might be related somehow - even if it's not directly an add-on that modifies XFMG in any way.
  11. batpool52!

    batpool52! Well-Known Member

    I never do code modifications to the official add-on for some reason. I tried something and found out that the media with content id 3 is not even included recounting process. I'll send you the screenshot of what I mean.
  12. Chris D

    Chris D XenForo Developer Staff Member

    I think it was only rebuilding comment counts for image uploads and skipping video embeds. Should be sorted now, thanks for your efforts in getting to the bottom of that :)
    batpool52! likes this.

Share This Page