Fixed Incorrect Comments Count

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?
 
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).
 
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.
 
I don't think it has any relevance here, but bear in mind the correct query would be:

Code:
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:

Code:
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?

Code:
SELECT comment_count FROM xengallery_media WHERE media_id = 3
 
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.
 
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.
 
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 :)
 
Top Bottom