Updating topic count in categories after bulk delete & missing topics/posts

I had a similar problem.

The following code (to be run within rails console) may solve your problem, make it worse, or set your hair on fire :fire:. Use at your own risk (and with a backup).

Category.all.each { |c|
    c.topic_count = c.topics.length - 1 # -1 for about post
    c.save!
}

Alternatively, rake import:ensure_consistency from here might help, but it seems to have destructive side effects.