ספירת קטגוריה שלילית (מספר מינוס) לאחר הסרה מרשימה/מחיקה

סיכום מבוסס בינה מלאכותית

Users reported an issue where unlisting and then deleting topics caused a negative category count (e.g., “-11 total”) in the Uncategorised category. Jonathan5 observed that topics previously unlisted and later deleted seemed to be subtracted twice from the category’s stats. simon confirmed the bug: unlisting doesn’t immediately affect stats (it waits for the daily CategoryStats job), but deleting does — so deleting an already unlisted topic subtracts it again. The issue resolves automatically after 24 hours when the job runs again, or can be fixed manually via Category.update_stats in the Rails console. Jonathan5 confirmed it self-corrected. Later, nbianca noted the issue was no longer reproducible and simon clarified reproduction requires waiting ~24 hours between unlisting and deletion. A fix was submitted for review here and will be available in a future version. Jonathan5 noted the issue likely only affects small or new forums and suggested updating the solution, but couldn’t edit the post.

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

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 לייקים

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 לייקים

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 לייקים

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