Can the topic count for a category be forced to update after the topics have been moved to a different category?
I used this method to move topics around after merging two forums, but the counts are still off after 1.5 days.
https://meta.discourse.org/t/bulk-move-many-topics-from-one-category-to-another/38704/2
If you execute either of these, category stats will be wrong but should fix themselves after a day.
Shouldn’t the category counts rebuild after a day @neil ?
fefrei
(Felix Freiberger)
October 30, 2017, 9:20am
3
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 , so backup accordingly
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 )
neil
(Neil Lalonde)
October 30, 2017, 5:39pm
4
Yes this is happenings once a day , doing this to update the counts:
after_destroy :clear_subcategory_ids
after_destroy :publish_category_deletion
after_destroy :remove_site_settings
after_save :reset_topic_ids_cache
after_save :clear_subcategory_ids
after_save :clear_url_cache
after_save :publish_discourse_stylesheet
after_save :publish_category
after_save do
if saved_change_to_uploaded_logo_id? || saved_change_to_uploaded_logo_dark_id? ||
saved_change_to_uploaded_background_id? || saved_change_to_uploaded_background_dark_id?
upload_ids = [
uploaded_logo_id,
uploaded_logo_dark_id,
Seems to work for me.
@fefrei @omarfilip Please go to sidekiq scheduler (/sidekiq/scheduler) and see what the last run of CategoryStats shows.
I’ve triggered mine manually yesterday so the scheduler won’t mean much right now:
The manual triggering of CategoryStats did not change the counts, though.
I ran Felix’s ruby code earlier today and that dropped the topic counts in the empty categories. It did not increase the topic count elsewhere like I thought it would.
fefrei
(Felix Freiberger)
October 30, 2017, 6:02pm
6
I had also triggered that job manually, as far as I recall. It completed successfully, but had no effect.
jerdog
(Jeremy M)
January 23, 2018, 2:27pm
7
Mine also ran but didn’t change the counts. I also have one which is -1 as well.
I will run the code from @fefrei and see if that makes a difference.
Edit: running the code worked in the rails console