Top topics not working after import

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.

1 Like

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

1 Like

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.

1 Like

Hmm, looking at the code we have two jobs — TopRefreshToday (fires every hour) and TopRefreshOlder (fires every 24 hours). Both call methods from here 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?

3 Likes

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:

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.

2 Likes

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

So maybe something like:

Topic.all.find_each do |t|
  putc '.'
  t.update_action_counts
end
4 Likes

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

3 Likes