Skip to content

fix(categories): eliminate N+1 query in dropdowns controller - #3158

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/category-dropdown-n1
Open

fix(categories): eliminate N+1 query in dropdowns controller#3158
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/category-dropdown-n1

Conversation

@sentry

@sentry sentry Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an N+1 query issue in Category::DropdownsController#show.

The categories_scope method was updated to include .includes(:parent). Previously, the view was iterating over categories and accessing their parent association, leading to a separate database query for each category to fetch its parent. By eager-loading the parent association, 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants