mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
DEV: No longer preload categories (#24950)
Categories will no longer be preloaded when `lazy_load_categories` is enabled through PreloadStore. Instead, the list of site categories will continue to be populated by `Site.updateCategory` as more and more categories are being loaded from different sources (topic lists, category selectors, etc).
This commit is contained in:
@ -9,7 +9,7 @@ export default {
|
|||||||
this.site = owner.lookup("service:site");
|
this.site = owner.lookup("service:site");
|
||||||
|
|
||||||
// If the site is login_required and the user is anon there will be no categories preloaded.
|
// If the site is login_required and the user is anon there will be no categories preloaded.
|
||||||
if (!this.site.categories) {
|
if (!this.site.categories?.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ export default {
|
|||||||
this.site = owner.lookup("service:site");
|
this.site = owner.lookup("service:site");
|
||||||
|
|
||||||
// If the site is login_required and the user is anon there will be no categories preloaded.
|
// If the site is login_required and the user is anon there will be no categories preloaded.
|
||||||
if (!this.site.categories) {
|
if (!this.site.categories?.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export default {
|
|||||||
// If the site is login_required and the user is anon there will be no categories
|
// If the site is login_required and the user is anon there will be no categories
|
||||||
// preloaded, so there will be no category color CSS variables generated by
|
// preloaded, so there will be no category color CSS variables generated by
|
||||||
// the category-color-css-generator initializer.
|
// the category-color-css-generator initializer.
|
||||||
if (!this.site.categories) {
|
if (!this.site.categories?.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ const Site = RestModel.extend({
|
|||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
this.topicCountDesc = ["topic_count:desc"];
|
this.topicCountDesc = ["topic_count:desc"];
|
||||||
|
this.categories = this.categories || [];
|
||||||
},
|
},
|
||||||
|
|
||||||
@discourseComputed("notification_types")
|
@discourseComputed("notification_types")
|
||||||
|
@ -4,9 +4,6 @@
|
|||||||
class Site
|
class Site
|
||||||
include ActiveModel::Serialization
|
include ActiveModel::Serialization
|
||||||
|
|
||||||
# Number of categories preloaded when lazy_load_categories is enabled
|
|
||||||
LAZY_LOAD_CATEGORIES_LIMIT = 10
|
|
||||||
|
|
||||||
cattr_accessor :preloaded_category_custom_fields
|
cattr_accessor :preloaded_category_custom_fields
|
||||||
|
|
||||||
def self.reset_preloaded_category_custom_fields
|
def self.reset_preloaded_category_custom_fields
|
||||||
@ -157,11 +154,7 @@ class Site
|
|||||||
|
|
||||||
self.class.categories_callbacks.each { |callback| callback.call(categories, @guardian) }
|
self.class.categories_callbacks.each { |callback| callback.call(categories, @guardian) }
|
||||||
|
|
||||||
if SiteSetting.lazy_load_categories
|
categories
|
||||||
categories[0...Site::LAZY_LOAD_CATEGORIES_LIMIT]
|
|
||||||
else
|
|
||||||
categories
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -238,6 +238,10 @@ class SiteSerializer < ApplicationSerializer
|
|||||||
object.categories.map { |c| c.to_h }
|
object.categories.map { |c| c.to_h }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def include_categories?
|
||||||
|
!SiteSetting.lazy_load_categories
|
||||||
|
end
|
||||||
|
|
||||||
def markdown_additional_options
|
def markdown_additional_options
|
||||||
Site.markdown_additional_options
|
Site.markdown_additional_options
|
||||||
end
|
end
|
||||||
|
@ -183,17 +183,6 @@ RSpec.describe Site do
|
|||||||
DiscoursePluginRegistry.clear_modifiers!
|
DiscoursePluginRegistry.clear_modifiers!
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
it "omits groups user can not see" do
|
it "omits groups user can not see" do
|
||||||
|
@ -131,6 +131,14 @@ RSpec.describe SiteSerializer do
|
|||||||
expect(serialized[:shared_drafts_category_id]).to eq(nil)
|
expect(serialized[:shared_drafts_category_id]).to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "does not include categories if lazy_load_categories" do
|
||||||
|
SiteSetting.lazy_load_categories = true
|
||||||
|
|
||||||
|
serialized = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
||||||
|
|
||||||
|
expect(serialized[:categories]).to eq(nil)
|
||||||
|
end
|
||||||
|
|
||||||
describe "#anonymous_default_navigation_menu_tags" do
|
describe "#anonymous_default_navigation_menu_tags" do
|
||||||
fab!(:user)
|
fab!(:user)
|
||||||
fab!(:tag) { Fabricate(:tag, name: "dev", description: "some description") }
|
fab!(:tag) { Fabricate(:tag, name: "dev", description: "some description") }
|
||||||
|
Reference in New Issue
Block a user