Is it possible to force a recalculation of created topic and created post counts?


I have an issue where the topic and post counts of my users are occasionally being calculated incorrectly. I’m not sure of the cause of that bug, but it’s causing truly confounding issues where post counts are actually negative, which ultimately forces the users into a state where new posts require moderation to persist.

Is there a way to force recalculating the topic/post count in the database, similar to how posts can be rebaked?

(Jeff Atwood) #2

Negative is usually due to deletions or other edge conditions, and these are bugs. Can you provide specific examples?


Unfortunately I haven’t been able to readily reproduce it, but it does still occur somewhat randomly. Deletions do seem to be a factor.

I’ll try to find some reproduction steps, but in the meantime, is there a way to force a recalculation of the post count? I can go to straight to the database, of course, but if there’s already a rake task or a SQL script or something that’d be great to know about.


I’ve confirmed with some recent cases that an admin deleting topics with a single post created by the user can decrement that user’s post count, even making it negative. This suggests that the post count was not correctly incremented or was possibly decremented twice, but I haven’t seen any direct evidence of the latter.

A sane sounding guard that would at least solve the problem I’m having would be to ensure that the post count is never decremented to be below zero?

(Sam Saffron) #5

Does the issue persist over time? We have some safeguards that run daily (or weekly)


Yes, though it’s somewhat intermittent. Digging through our self-hosted instance I was able to find months-old users that had this symptom.

Do the safeguards do any kind of logging? I can scan the logs and confirm whether they’ve run if/when this pops up again.