# 自引入部分加载类别以来，用户无法编辑类别导航

**URL:** https://meta.discourse.org/t/users-are-not-able-to-edit-category-navigation-since-introduction-of-partial-loaded-categories/337854
**Category:** Bug
**Tags:** fixed
**Created:** [2024年十一月22日 23:52 UTC](https://meta.discourse.org/t/users-are-not-able-to-edit-category-navigation-since-introduction-of-partial-loaded-categories/337854 "2024-11-22T23:52:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![thoka](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thoka/32/115652_2.png) [@thoka](https://meta.discourse.org/u/thoka)
#### Post date: [2024年十一月22日 23:52 UTC](https://meta.discourse.org/t/users-are-not-able-to-edit-category-navigation-since-introduction-of-partial-loaded-categories/337854/1 "2024-11-22T23:52:35Z")

</div>

我们有很多类别，只有一小部分对普通用户可见。

除了管理员，大多数用户在“编辑类别导航”模态框中都看不到子类别。

如果我将 `Category scope :limited_categories_matching`（[来源](https://github.com/discourse/discourse/blob/d880db3b7b748901366d0c94f58dada9096f967f/app/models/category.rb#L395-L404)）中包含的子类别数量从 5 增加到某个数字，从而有效地禁用部分加载，那么缺失的类别就会显示出来。

我的猜测是，除非用户可见的子类别恰好在前五个子类别中，否则它们将被权限检查从结果集中删除，导致编辑器中缺少“加载更多”元素。

如果搜索结果的数量可以配置，我将非常满意，作为一个快速修复。

附注：`categories-modal.gjs` 假设有更多类别需要加载[如果显示的类别数量为 5](https://github.com/discourse/discourse/blob/d880db3b7b748901366d0c94f58dada9096f967f/app/assets/javascripts/discourse/app/components/sidebar/edit-navigation-menu/categories-modal.gjs#L97)，即使使用上面的补丁加载了所有子类别，并且显示的类别数量恰好为 5 时，也会发生这种情况。

与此同时，我使用此模板来修复此问题：

```plaintext
run:
  - replace:
      filename: "/var/www/discourse/app/models/category.rb"
      from: "select_descendants(Category.from(\"matches\").select(:matches, :id), 5)"
      to: "select_descendants(Category.from(\"matches\").select(:matches, :id), 500)"

```

---

<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: [2024年十一月25日 18:08 UTC](https://meta.discourse.org/t/users-are-not-able-to-edit-category-navigation-since-introduction-of-partial-loaded-categories/337854/4 "2024-11-25T18:08:05Z")

</div>

感谢您的 Bug 报告，Thomas。我们已在此 PR 中实施了修复：

> <https://github.com/discourse/discourse/pull/29916>
>
> The hierarchical search for categories is composed of several complex nested que…ries. This change ensures that the secured categories are filtered out as soon as possible to ensure that the default limit of 5 categories is reached.
> 
> Without this fix, the search can return less than 5 categories if any of the first 5 categories cannot be displayed due to permissions.

---

<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: [2024年十一月28日 18:29 UTC](https://meta.discourse.org/t/users-are-not-able-to-edit-category-navigation-since-introduction-of-partial-loaded-categories/337854/6 "2024-11-28T18:29:10Z")

</div>

修复已合并，@thoka。现在应该可以正常工作了。 🙂

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2024年十二月1日 18:29 UTC](https://meta.discourse.org/t/users-are-not-able-to-edit-category-navigation-since-introduction-of-partial-loaded-categories/337854/7 "2024-12-01T18:29:13Z")

</div>

此主题在上次回复后 3 天自动关闭。不允许新的回复。
