Skip to content
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

Merged
merged 1 commit into from Nov 28, 2023
Merged

Conversation

nbianca
Copy link
Member

@nbianca nbianca commented Oct 31, 2023

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.

@nbianca nbianca force-pushed the fix_category_drop branch 2 times, most recently from fea5f6b to 5cf7425 Compare November 20, 2023 17:42
@nbianca nbianca marked this pull request as ready for review November 20, 2023 20:02
Comment on lines +33 to +36
const category = this.siteSettings.lazy_load_categories
? await Category.asyncFindBySlugPathWithID(
params.category_slug_path_with_id
)
Copy link
Contributor

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.

Copy link
Member Author

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.

app/models/category.rb Outdated Show resolved Hide resolved
@@ -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
Copy link
Contributor

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?

Copy link
Member Author

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.

app/models/topic_list.rb Outdated Show resolved Hide resolved
@@ -19,7 +19,7 @@ class BasicCategorySerializer < ApplicationSerializer
:notification_level,
:can_edit,
:topic_template,
:has_children,
:has_children?,
Copy link
Contributor

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.

Copy link
Member Author

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).

@nbianca nbianca force-pushed the fix_category_drop branch 2 times, most recently from 3a341d0 to 541b55d Compare November 23, 2023 17:04
@nbianca nbianca changed the title FIX: Avoid using categories list in computed property FIX: Make category-drop with lazy_load_categories Nov 23, 2023
@nbianca nbianca force-pushed the fix_category_drop branch 2 times, most recently from c40736d to 46decc7 Compare November 24, 2023 14:43
@nbianca nbianca changed the title FIX: Make category-drop with lazy_load_categories FIX: Make category-drop work with lazy_load_categories Nov 27, 2023
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.
@nbianca nbianca merged commit e85a81f into main Nov 28, 2023
19 checks passed
@nbianca nbianca deleted the fix_category_drop branch November 28, 2023 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants