# Force recount of topics in category after moving them

**URL:** https://meta.discourse.org/t/force-recount-of-topics-in-category-after-moving-them/73026
**Category:** Support
**Created:** [30 oktober 2017 om 03:37 UTC](https://meta.discourse.org/t/force-recount-of-topics-in-category-after-moving-them/73026 "2017-10-30T03:37:10Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![fefrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fefrei/32/119538_2.png) [@fefrei](https://meta.discourse.org/u/fefrei)
#### Post date: [30 oktober 2017 om 09:20 UTC](https://meta.discourse.org/t/force-recount-of-topics-in-category-after-moving-them/73026/3 "2017-10-30T09:20:25Z")

</div>

It would be nice if they did! However, that didn’t work out for us [when we did a similar move](https://meta.discourse.org/t/re-purposing-a-discourse-installation-for-a-yearly-event/34670/17).

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

```ruby
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](https://meta.discourse.org/t/wrong-post-count-in-profile/71352/41) 🙂)

---

_[View the full topic](https://meta.discourse.org/t/force-recount-of-topics-in-category-after-moving-them/73026)._
