Skip to content

Replace some AR calls to first with take#2889

Merged
jmhooper merged 9 commits intomasterfrom
jmhooper-replace-first-with-take
Apr 15, 2019
Merged

Replace some AR calls to first with take#2889
jmhooper merged 9 commits intomasterfrom
jmhooper-replace-first-with-take

Conversation

@jmhooper
Copy link
Contributor

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.

**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.
Copy link

@lauraGgit lauraGgit left a 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

stevegsa
stevegsa previously approved these changes Apr 12, 2019
Copy link
Contributor

@stevegsa stevegsa left a comment

Choose a reason for hiding this comment

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

NICE!

@lauraGgit
Copy link

@jmhooper do you think that you'll be able to add a note on the PR template related to the take?

@jmhooper
Copy link
Contributor Author

@lauraGgit: I added a note to the "Database" section of the PR template

Copy link

@lauraGgit lauraGgit left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

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.

3 participants