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

Use includes instead of eager_load for with_all_rich_text #50769

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

p8
Copy link
Member

@p8 p8 commented Jan 16, 2024

Motivation / Background

eager_load performs a single query using a LEFT OUTER JOIN to load the associations. Loading the associations in a join can result in many rows that contain redundant data and it performs poorly at scale.

With includes a separate query is performed for each association, unless a join is required by conditions.

includes is also used by similar methods in Active Storage like with_attached_*.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot bot added the actiontext label Jan 16, 2024
`eager_load` performs a single query using a `LEFT OUTER JOIN` to load
the associations. Loading the associations in a join can result in many
rows that contain redundant data and it performs poorly at scale.

With `includes` a separate query is performed for each association,
unless a join is required by conditions.

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
@p8 p8 force-pushed the actiontext/eager-load-with-includes branch from 632f1b1 to 3b49e47 Compare January 16, 2024 21:06
@rafaelfranca rafaelfranca merged commit 473fd59 into rails:main Jan 16, 2024
3 of 4 checks passed
@p8 p8 deleted the actiontext/eager-load-with-includes branch January 17, 2024 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants