mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 13:03:16 +08:00
FIX: Preload all ancestors of sidebar categories (#26715)
... instead of just the immediate parents.
This commit is contained in:
parent
a6b8051645
commit
e2ceea8815
|
@ -111,12 +111,7 @@ class Site
|
||||||
if @guardian.authenticated?
|
if @guardian.authenticated?
|
||||||
sidebar_category_ids = @guardian.user.secured_sidebar_category_ids(@guardian)
|
sidebar_category_ids = @guardian.user.secured_sidebar_category_ids(@guardian)
|
||||||
preloaded_category_ids.concat(
|
preloaded_category_ids.concat(
|
||||||
Category
|
Category.secured(@guardian).ancestors_of(sidebar_category_ids).pluck(:id),
|
||||||
.secured(@guardian)
|
|
||||||
.select(:parent_category_id)
|
|
||||||
.distinct
|
|
||||||
.where(id: sidebar_category_ids)
|
|
||||||
.pluck(:parent_category_id),
|
|
||||||
)
|
)
|
||||||
preloaded_category_ids.concat(sidebar_category_ids)
|
preloaded_category_ids.concat(sidebar_category_ids)
|
||||||
end
|
end
|
||||||
|
|
|
@ -195,14 +195,17 @@ RSpec.describe Site do
|
||||||
expect(site.categories).to eq([])
|
expect(site.categories).to eq([])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns only sidebar categories and their parent categories" do
|
it "returns only sidebar categories and their ancestors" do
|
||||||
parent_category = Fabricate(:category)
|
SiteSetting.max_category_nesting = 3
|
||||||
|
grandfather_category = Fabricate(:category)
|
||||||
|
parent_category = Fabricate(:category, parent_category: grandfather_category)
|
||||||
category.update!(parent_category: parent_category)
|
category.update!(parent_category: parent_category)
|
||||||
Fabricate(:category_sidebar_section_link, linkable: category, user: user)
|
Fabricate(:category_sidebar_section_link, linkable: category, user: user)
|
||||||
|
|
||||||
site = Site.new(Guardian.new(user))
|
site = Site.new(Guardian.new(user))
|
||||||
|
|
||||||
expect(site.categories.map { |c| c[:id] }).to contain_exactly(
|
expect(site.categories.map { |c| c[:id] }).to contain_exactly(
|
||||||
|
grandfather_category.id,
|
||||||
parent_category.id,
|
parent_category.id,
|
||||||
category.id,
|
category.id,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user