mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 02:11:08 -06:00
DEV: Limit preloaded categories (#23958)
Site data is preloaded on the first page load, which includes categories data. For sites with many categories, site data takes a long time to serialize and to transfer. In the future, preloaded category data will be completely removed.
This commit is contained in:
parent
2e68ead45b
commit
bf97899029
@ -4,6 +4,9 @@
|
||||
class Site
|
||||
include ActiveModel::Serialization
|
||||
|
||||
# Number of categories preloaded when lazy_load_categories is enabled
|
||||
LAZY_LOAD_CATEGORIES_LIMIT = 50
|
||||
|
||||
cattr_accessor :preloaded_category_custom_fields
|
||||
|
||||
def self.reset_preloaded_category_custom_fields
|
||||
@ -116,6 +119,10 @@ class Site
|
||||
)
|
||||
categories << category
|
||||
end
|
||||
|
||||
if SiteSetting.lazy_load_categories && categories.size >= Site::LAZY_LOAD_CATEGORIES_LIMIT
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
with_children = Set.new
|
||||
|
@ -183,6 +183,17 @@ RSpec.describe Site do
|
||||
DiscoursePluginRegistry.clear_modifiers!
|
||||
end
|
||||
end
|
||||
|
||||
context "when lazy_load_categories" do
|
||||
before { SiteSetting.lazy_load_categories = true }
|
||||
|
||||
it "limits the number of categories" do
|
||||
stub_const(Site, "LAZY_LOAD_CATEGORIES_LIMIT", 1) do
|
||||
categories = Site.new(Guardian.new).categories
|
||||
expect(categories.size).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "omits groups user can not see" do
|
||||
|
Loading…
Reference in New Issue
Block a user