A platform for community discussion. Free, open, simple.
DEV: Limit preloaded categories (#23958)
Bianca Nenciubf97899029d6
diff --git a/app/models/site.rb b/app/models/site.rbindex e56709499e5..07c82ff0914 100644--- a/app/models/site.rb+++ b/app/models/site.rb@@ -4,6 +4,9 @@class Siteinclude ActiveModel::Serialization+ # Number of categories preloaded when lazy_load_categories is enabled+ LAZY_LOAD_CATEGORIES_LIMIT = 50+cattr_accessor :preloaded_category_custom_fieldsdef self.reset_preloaded_category_custom_fields@@ -116,6 +119,10 @@ class Site)categories << categoryend++ if SiteSetting.lazy_load_categories && categories.size >= Site::LAZY_LOAD_CATEGORIES_LIMIT+ break+ endendwith_children = Set.newdiff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rbindex 4a5849eaf1d..67267817822 100644--- a/spec/models/site_spec.rb+++ b/spec/models/site_spec.rb@@ -183,6 +183,17 @@ RSpec.describe Site doDiscoursePluginRegistry.clear_modifiers!endend++ 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+ endendit "omits groups user can not see" do