fix(categories): eliminate N+1 query in dropdowns controller - #3158
fix(categories): eliminate N+1 query in dropdowns controller#3158sentry[bot] wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68f3a13031
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| def categories_scope | ||
| Current.family.categories.alphabetically | ||
| Current.family.categories.includes(:parent).alphabetically |
There was a problem hiding this comment.
Remove the unused parent preload
For families with subcategories, this adds a parent-preload query and allocates another set of Category records on every dropdown request, but the rendered path never reads the association: Category::Group.for groups by parent_id, _row.html.erb checks parent_id, and Category#display_name does not access parent. The same row partial also renders @recent_categories without preloading parents. Thus this change does not eliminate an N+1 in this action and instead introduces fixed query and memory overhead.
Useful? React with 👍 / 👎.
This PR addresses an N+1 query issue in
Category::DropdownsController#show.The
categories_scopemethod was updated to include.includes(:parent). Previously, the view was iterating over categories and accessing theirparentassociation, leading to a separate database query for each category to fetch its parent. By eager-loading theparentassociation, this change reduces the number of database queries and improves performance.Fixes SURE-APP-167
This PR was automatically generated by Sentry. You can adjust this setting at any time.