mirror of
https://github.com/discourse/discourse.git
synced 2025-01-20 03:42:44 +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:
parent
c4396c6acf
commit
14269232ba
|
@ -9,7 +9,7 @@ export default {
|
|||
this.site = owner.lookup("service:site");
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ export default {
|
|||
this.site = owner.lookup("service:site");
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ export default {
|
|||
// 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
|
||||
// the category-color-css-generator initializer.
|
||||
if (!this.site.categories) {
|
||||
if (!this.site.categories?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ const Site = RestModel.extend({
|
|||
this._super(...arguments);
|
||||
|
||||
this.topicCountDesc = ["topic_count:desc"];
|
||||
this.categories = this.categories || [];
|
||||
},
|
||||
|
||||
@discourseComputed("notification_types")
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
class Site
|
||||
include ActiveModel::Serialization
|
||||
|
||||
# Number of categories preloaded when lazy_load_categories is enabled
|
||||
LAZY_LOAD_CATEGORIES_LIMIT = 10
|
||||
|
||||
cattr_accessor :preloaded_category_custom_fields
|
||||
|
||||
def self.reset_preloaded_category_custom_fields
|
||||
|
@ -157,13 +154,9 @@ class Site
|
|||
|
||||
self.class.categories_callbacks.each { |callback| callback.call(categories, @guardian) }
|
||||
|
||||
if SiteSetting.lazy_load_categories
|
||||
categories[0...Site::LAZY_LOAD_CATEGORIES_LIMIT]
|
||||
else
|
||||
categories
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def groups
|
||||
query =
|
||||
|
|
|
@ -238,6 +238,10 @@ class SiteSerializer < ApplicationSerializer
|
|||
object.categories.map { |c| c.to_h }
|
||||
end
|
||||
|
||||
def include_categories?
|
||||
!SiteSetting.lazy_load_categories
|
||||
end
|
||||
|
||||
def markdown_additional_options
|
||||
Site.markdown_additional_options
|
||||
end
|
||||
|
|
|
@ -183,17 +183,6 @@ 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
|
||||
|
|
|
@ -131,6 +131,14 @@ RSpec.describe SiteSerializer do
|
|||
expect(serialized[:shared_drafts_category_id]).to eq(nil)
|
||||
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
|
||||
fab!(:user)
|
||||
fab!(:tag) { Fabricate(:tag, name: "dev", description: "some description") }
|
||||
|
|
Loading…
Reference in New Issue
Block a user