I’ve unlisted and deleted some topics from the Uncategorised category today, and now the main category-list page says “-11 total” for that category.
Thinking about it - most of the topics I deleted had previously been unlisted. I wonder whether that is relevant - maybe unlisting and deleting each separately deducts 1 from the count per topic.
Will this right itself automatically (over time or when some event happens)?
Yes, that’s the problem. I can reproduce the issue on my test site. Unlisting a topic removes the topic from its category’s topic stats. If you then delete the unlisted topic, it is again subtracted from its category’s topic stats. This means that unlisting and then deleting a single topic is counted as removing two topics from the stats.
Discourse runs a CategoryStats background job once every 24 hours. When that job runs, the stats for your category should get fixed. If you have access to your site’s rails console, and don’t want to wait for the job to run, you can run the command manually with:
Category.update_stats
I tested this on my own site. Running that command fixed the issue for me.
It turns out that to reproduce the issue, you need to unlist a topic, wait approximately 24 hours for the category stats job to run, and then delete the topic. That will cause the topic to have been removed twice from the category stats. After another 24 hours, the category stats job will have been run again. That should resolve the issue.
The reason this happens is that deleting a topic immediately removes the topic from the category stats. Unlisting a topic does not cause the topic to be removed from the stats until the daily job is run to update the category’s stats - that job checks for visible topics.