New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Make category-drop work with lazy_load_categories #24187
Conversation
b2cc5ed
to
0e06559
Compare
fea5f6b
to
5cf7425
Compare
4b3ec65
to
9971771
Compare
app/assets/javascripts/discourse/app/components/bread-crumbs.hbs
Outdated
Show resolved
Hide resolved
app/assets/javascripts/discourse/app/instance-initializers/category-badge-css-generator.js
Outdated
Show resolved
Hide resolved
const category = this.siteSettings.lazy_load_categories | ||
? await Category.asyncFindBySlugPathWithID( | ||
params.category_slug_path_with_id | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the context of this PR, what problem is this solving? Also, I wonder if we should first check if the category has already been preloaded instead of triggering a network request to fetch the categories unconditionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no. I mean it is not a direct fix to category-drop, but navigating using category-drop is broken otherwise.
@@ -5,7 +5,7 @@ class Site | |||
include ActiveModel::Serialization | |||
|
|||
# Number of categories preloaded when lazy_load_categories is enabled | |||
LAZY_LOAD_CATEGORIES_LIMIT = 50 | |||
LAZY_LOAD_CATEGORIES_LIMIT = 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we are reducing the limit here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make other category scaling bugs more obvious, but I can move to a different PR.
@@ -19,7 +19,7 @@ class BasicCategorySerializer < ApplicationSerializer | |||
:notification_level, | |||
:can_edit, | |||
:topic_template, | |||
:has_children, | |||
:has_children?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ?
allowed in the attribute name? Im wondering if there is an existing test for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a test, but it was broken. The serializer types were "string/null", but it should've been "bool".
Attribute names containing characters such as a question mark are sanitized and only has_children
is returned. The question mark is necessary because we want to serialize category.has_children?
(which exists) instead of category.has_children
(which does not exist).
3a341d0
to
541b55d
Compare
c40736d
to
46decc7
Compare
The category drop was rerendered after every category async change because it updated the categories list. This is not necessary and categories can be referenced indirectly by ID instead.
46decc7
to
8ab65a7
Compare
The category drop was rerendered after every category async search because it updated the categories list stored in the Site instance. This is not necessary and categories can be referenced indirectly by ID instead to avoid loading objects.
This PR contains other various bug fixes to make it mostly work as expected.