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: n+1 issues in case_contacts#index #5868

Merged

Conversation

elasticspoon
Copy link
Collaborator

CaseContactsController#index was our worst page according to scout.

image
image

This was mainly because we had 2 N+1 queries:
image

Those have been fixed.

@github-actions github-actions bot added ruby Pull requests that update Ruby code erb labels Jun 28, 2024
@elasticspoon elasticspoon force-pushed the fix/n+1-in-case_contacts#index branch from f3c5f55 to 858bc09 Compare June 28, 2024 01:12
followups.requested.first
followups.find(&:requested?)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are including followups in the query already, however, the call to .requested forces another query Followups.where(case_id: id, status: 0) because it needs to check the status. Since all the data is already loaded it makes more sense to check that status in ruby rather than making another request.

@elasticspoon elasticspoon marked this pull request as ready for review June 28, 2024 01:34
@compwron compwron merged commit 48fc965 into rubyforgood:main Jun 29, 2024
17 of 18 checks passed
@elasticspoon
Copy link
Collaborator Author

image
💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
erb ruby Pull requests that update Ruby code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants