Force recount of topics in category after moving them

It would be nice if they did! However, that didn’t work out for us when we did a similar move.

The following Ruby code, executed in the Rails console, will either fix the issue or set your database on fire :fire:, so backup accordingly :wink:

Category.find_each { |c|
    c.topic_count = Topic.where(category: c).count - 1 # -1 for about post
    c.save!
}

(I’d still love for these to be re-counted occasionally, just as I’d do for post counts :slight_smile:)

3 Likes