Negative category count (minus number) after unlisting/deleting

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)?

Or is there something I should do to fix it?

Thanks.

(Edited to tidy up.)

1 Like

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.

4 Likes

Thanks. I’m happy to wait but that is good to know.

P.S. I can now confirm that it fixed itself! :slight_smile:

Hello Jonathan,

We are no longer able to reproduce this issue. Do you still see it happening in the latest version?

I’ve got 2.7.0.beta2 (afbaedef7d) installed - not the latest - so maybe that’s relevant.

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.

4 Likes

Hello,

We identified the problem and I just submitted a fix for review. It will be available in the latest version soon.

https://github.com/discourse/discourse/pull/11946

2 Likes

That’s great. I don’t imagine it caused much of a problem. Maybe only noticeable in small/new forums.

I’d change the “Solution” to the final post here but it won’t let me.

1 Like