# Top topics not working after import

**URL:** https://meta.discourse.org/t/top-topics-not-working-after-import/184544
**Category:** Support
**Created:** [March 26, 2021, 10:08am UTC](https://meta.discourse.org/t/top-topics-not-working-after-import/184544 "2021-03-26T10:08:26Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![TheDarkWizard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thedarkwizard/32/177913_2.png) [@TheDarkWizard](https://meta.discourse.org/u/TheDarkWizard)
#### Post date: [March 26, 2021, 10:08am UTC](https://meta.discourse.org/t/top-topics-not-working-after-import/184544/1 "2021-03-26T10:08:26Z")

</div>

Any way to get Discourse to recalculate all Top Topics in a user’s profile after an import and/or links counter in a topic?

Oddly enough, Top Replies is working correctly.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [March 26, 2021, 1:51pm UTC](https://meta.discourse.org/t/top-topics-not-working-after-import/184544/2 "2021-03-26T13:51:48Z")

</div>

I _believe_ the stats are calculated automatically every 24 hours. You shouldn’t need to do anything but wait.

---

<div class="post-metadata">

### Author: ![TheDarkWizard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thedarkwizard/32/177913_2.png) [@TheDarkWizard](https://meta.discourse.org/u/TheDarkWizard)
#### Post date: [March 26, 2021, 10:09pm UTC](https://meta.discourse.org/t/top-topics-not-working-after-import/184544/3 "2021-03-26T22:09:26Z")

</div>

That doesn’t seem to be the case, we’ve had an import test up and running for a few weeks now, somethings self corrected, others did not. Top Topics is the biggest example of this. Amount Links in topics is the other. Other then that, seems to be correct across the site.

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [March 26, 2021, 10:22pm UTC](https://meta.discourse.org/t/top-topics-not-working-after-import/184544/4 "2021-03-26T22:22:21Z")

</div>

Hmm, looking at the code we have two jobs — [TopRefreshToday](https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/top_refresh_today.rb) (fires every hour) and [TopRefreshOlder](https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/top_refresh_older.rb) (fires every 24 hours). Both call methods from [here](https://github.com/discourse/discourse/blob/master/app/models/top_topic.rb) which you should be able to run from the rails console manually if needed.

Can you check `/sidekiq/scheduler` to see if the two jobs have been running?

I’m assuming all of the relevant information for calculating top topics was brought over with the import?

---

<div class="post-metadata">

### Author: ![Ghan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ghan/32/177964_2.png) [@Ghan](https://meta.discourse.org/u/Ghan)
#### Post date: [March 27, 2021, 12:47am UTC](https://meta.discourse.org/t/top-topics-not-working-after-import/184544/5 "2021-03-27T00:47:18Z")

</div>

In this case, these jobs are running just fine. The issue appears to be that the like\_count field on the topics table is not populated. Is there a good way to recalculate the value for that field, or is that something that needs to be done during import? If it does need to be done during import, then how is the calculation for that supposed to work? Is this a summation of all likes from all posts in the topic?

I did find a way using the Rails console that appears to recalculate this field:

```plaintext
Topic.visible.map(&:update_statistics)

```

The issue with this solution is that for our topic and post counts, I was estimating it would take about two months for that command to run to completion.

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [March 27, 2021, 1:47am UTC](https://meta.discourse.org/t/top-topics-not-working-after-import/184544/6 "2021-03-27T01:47:14Z")

</div>

It looks like you can regenerate the `like_count` using the `update_action_counts` method:

> <https://github.com/discourse/discourse/blob/fb19ee9eee15e721ce8fe8d326fa7b8af36e9f46/app/models/topic.rb#L1107>

So maybe something like:

```ruby
Topic.all.find_each do |t|
  putc '.'
  t.update_action_counts
end

```

---

<div class="post-metadata">

### Author: ![TheDarkWizard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thedarkwizard/32/177913_2.png) [@TheDarkWizard](https://meta.discourse.org/u/TheDarkWizard)
#### Post date: [March 29, 2021, 4:23pm UTC](https://meta.discourse.org/t/top-topics-not-working-after-import/184544/7 "2021-03-29T16:23:32Z")

</div>

This appears to have worked really well for @Ghan and I, thank you so much 🙂

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 28, 2021, 4:24pm UTC](https://meta.discourse.org/t/top-topics-not-working-after-import/184544/8 "2021-04-28T16:24:33Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
