mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 13:12:45 +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?
|
||||
sidebar_category_ids = @guardian.user.secured_sidebar_category_ids(@guardian)
|
||||
preloaded_category_ids.concat(
|
||||
Category
|
||||
.secured(@guardian)
|
||||
.select(:parent_category_id)
|
||||
.distinct
|
||||
.where(id: sidebar_category_ids)
|
||||
.pluck(:parent_category_id),
|
||||
Category.secured(@guardian).ancestors_of(sidebar_category_ids).pluck(:id),
|
||||
)
|
||||
preloaded_category_ids.concat(sidebar_category_ids)
|
||||
end
|
||||
|
|
|
@ -195,14 +195,17 @@ RSpec.describe Site do
|
|||
expect(site.categories).to eq([])
|
||||
end
|
||||
|
||||
it "returns only sidebar categories and their parent categories" do
|
||||
parent_category = Fabricate(:category)
|
||||
it "returns only sidebar categories and their ancestors" do
|
||||
SiteSetting.max_category_nesting = 3
|
||||
grandfather_category = Fabricate(:category)
|
||||
parent_category = Fabricate(:category, parent_category: grandfather_category)
|
||||
category.update!(parent_category: parent_category)
|
||||
Fabricate(:category_sidebar_section_link, linkable: category, user: user)
|
||||
|
||||
site = Site.new(Guardian.new(user))
|
||||
|
||||
expect(site.categories.map { |c| c[:id] }).to contain_exactly(
|
||||
grandfather_category.id,
|
||||
parent_category.id,
|
||||
category.id,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user