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

where.first can be replaced by find_by #182

Open
lelelelemon opened this issue Aug 18, 2017 · 2 comments
Open

where.first can be replaced by find_by #182

lelelelemon opened this issue Aug 18, 2017 · 2 comments

Comments

@lelelelemon
Copy link
Collaborator

pp = self.variant_properties.where({ :variant_properties => {:primary => true}}).first

in order to avoid the unnecessary order by primary key operation

@drhenner
Copy link
Owner

👍

Yeah I think the SQL caching is better with find_by now days. Not sure if that was the case when I originally created this method.

@lelelelemon
Copy link
Collaborator Author

And I searched for other places, seems they can also be replaced:

app/controllers/shopping/orders_controller.rb: @order = Order.where(number: params[:id]).includes({order_items: :variant}).first
app/controllers/wish_items_controller.rb: item = current_user.wish_list_items.where(variant_id: params[:variant_id]).first
app/models/users_newsletter.rb: user = User.where(email: email).first
app/models/cart.rb: variant = Variant.where(id: variant_id).first

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

No branches or pull requests

2 participants