-
Notifications
You must be signed in to change notification settings - Fork 120
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
Replace some AR calls to first with take #2889
Conversation
**Why**: Using `#first` adds a sort by pkey to the query which results in a slower query, in some cases daramtically slower. In situations where we don't care how the records are sorted we should use `#take` for better performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add something to issue template about take
on ActiveRecord relations/ and possible in ruboCop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NICE!
@jmhooper do you think that you'll be able to add a note on the PR template related to the take? |
@lauraGgit: I added a note to the "Database" section of the PR template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
Why: Using
#first
adds a sort by pkey to the query which results in a slower query, in some cases daramtically slower. In situations where we don't care how the records are sorted we should use#take
for better performance.