# 取消列出/删除后负类别计数（减去数字）

**URL:** <https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556>\
**Category:** UX\
**Tags:** unlisting\
**Created:** [2021年一月28日 15:34 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556 "2021-01-28T15:34:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)\
**Post date:** [2021年一月28日 15:34 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556/1 "2021-01-28T15:34:23Z")

</div>

今天我取消了“未分类”类别中一些主题的公开状态并删除了它们，现在主类别列表页面显示该类别的总数为“-11”。

仔细想想——我删除的大多数主题之前已经被取消公开。不知道这是否相关——也许取消公开和删除分别会使每个主题的计数减少 1。

这个问题会自动修复吗（随时间推移或在某个事件发生时）？

或者我需要做些什么来修复它？

谢谢。

（已编辑以整理内容。）

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2021年一月28日 23:27 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556/2 "2021-01-28T23:27:39Z")

</div>

> [@Jonathan5](#):
>
> 仔细想想——我删除的大多数主题之前都被设为“未列出”。我在想这是否有关联——也许将主题“未列出”和“删除”分别操作，每个操作都会使该主题的计数减 1。

是的，这就是问题所在。我可以在我的测试站点上复现该问题。将主题设为“未列出”会从该分类的主题统计中移除该主题。如果你随后删除了这个未列出的主题，它又会再次从该分类的主题统计中被扣除。这意味着，对单个主题先执行“未列出”再执行“删除”，在统计中会被计为移除了两个主题。

Discourse 每 24 小时运行一次 `CategoryStats` 后台任务。当该任务运行时，你所在分类的统计信息应该会被修正。如果你能访问站点的 Rails 控制台，并且不想等待任务自动运行，可以手动执行以下命令：

```ruby
Category.update_stats

```

我在我自己的站点上测试过。运行该命令后，问题就解决了。

---

<div class="post-metadata">

**Author:** ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)\
**Post date:** [2021年一月28日 23:36 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556/3 "2021-01-28T23:36:39Z")

</div>

谢谢。我很乐意等待，但知道这一点很好。

附言：我现在可以确认它已经自行修复了！🙂

---

<div class="post-metadata">

**Author:** ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)\
**Post date:** [2021年二月2日 13:03 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556/11 "2021-02-02T13:03:11Z")

</div>

你好，Jonathan，

我们已无法复现此问题。在最新版本中您是否仍能看到该问题？

---

<div class="post-metadata">

**Author:** ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)\
**Post date:** [2021年二月2日 13:16 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556/12 "2021-02-02T13:16:54Z")

</div>

我安装了 2.7.0.beta2 (afbaedef7d) 版本——并非最新版——所以这可能相关。

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2021年二月3日 00:40 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556/16 "2021-02-03T00:40:32Z")

</div>

原来，要复现该问题，您需要取消列出某个主题，等待约 24 小时让分类统计任务运行，然后再删除该主题。这将导致该主题被从分类统计中移除两次。再过 24 小时后，分类统计任务将再次运行，这应能解决问题。

出现这种情况的原因是：删除主题会立即将其从分类统计中移除；而取消列出主题并不会导致该主题从统计中移除，直到每日任务运行以更新分类统计时才会处理——该任务会检查 `visible`（可见）主题。

---

<div class="post-metadata">

**Author:** ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)\
**Post date:** [2021年二月3日 15:15 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556/18 "2021-02-03T15:15:03Z")

</div>

您好，

我们已找到问题所在，并已提交修复方案供审核。该修复将很快在最新版本中提供。

> <https://github.com/discourse/discourse/pull/11946>
>
> Updating a topic's visibility did not increase or decrease the
> topic\_count of a… category, but Category.update\_stats does ignore
> unlisted topics which resulted in inconsistencies when deleting
> such topics.

---

<div class="post-metadata">

**Author:** ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)\
**Post date:** [2021年二月3日 17:46 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556/19 "2021-02-03T17:46:00Z")

</div>

太好了，我想这没造成什么大问题，可能只在小型或新论坛中比较明显。

我想把这里的“解决方案”改成最终回复，但系统不允许我这样做。

---

<div class="post-metadata">

**Author:** ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)\
**Post date:** [2021年二月16日 16:22 UTC](https://meta.discourse.org/t/negative-category-count-minus-number-after-unlisting-deleting/177556/20 "2021-02-16T16:22:08Z")

</div>


