Skip to content

#6496 n plus one cases cases index#6946

Merged
FireLemons merged 3 commits into
rubyforgood:mainfrom
andoq:andoq/6496_n_plus_one_cases_cases_index
May 13, 2026
Merged

#6496 n plus one cases cases index#6946
FireLemons merged 3 commits into
rubyforgood:mainfrom
andoq:andoq/6496_n_plus_one_cases_cases_index

Conversation

@andoq
Copy link
Copy Markdown

@andoq andoq commented May 11, 2026

What github issue is this PR for, if any?

Resolves #6496

What changed, and why?

  • use .size instead of .count, eager load the casa_case_emancipation_categories in the controller
  • memoize emancipation category count
    • NOTE: this wasn't strictly part of the ticket, and is probably a trivial cost do do a COUNT(*) on this table since there are a limited number of categories, but was easy to fix and covered in all the same testing, so I added it.

How is this tested? (please write rspec and jest tests!) 💖💪

  • ran all tests, but specifically:
    • emancipations_helper_spec
    • casa_cases_decorator_spec

Ran and loaded casa_cases_index page (/casa_cases) as a voluteer and as a supervisor
Ran and loaded case_cases_show page (/casa_cases/cina-10-1002) as a volunteer and as a supervisor.

Screenshots please :)

Here are screens of the server development log and queries before and after the change. Annotated where the queries are changed.

Before fix After fix
before_fix after_fix

Andrew Camp added 3 commits May 8, 2026 11:32
…ubyforgood#6496)

To avoid n+1 queries on the index page, eager load the casa_case_emancipation_categories in the controller, and then use .size instead of .count in the decorator.  Also memoized the emancipation_category_total_count so that we don't have to query for it for every row.
@github-actions github-actions Bot added 🧪 Tests Tests ruby Touches Ruby code labels May 11, 2026
@FireLemons FireLemons merged commit ea24660 into rubyforgood:main May 13, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Touches Ruby code 🧪 Tests Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

n plus one casa cases index page

2 participants