drhenner / ror_ecommerce

Ruby on Rails Ecommerce platform, perfect for your small business solution.
www.ror-e.com
MIT License
1.21k stars 409 forks source link

where.first can be replaced by find_by #182

Open lelelelemon opened 7 years ago

lelelelemon commented 7 years ago

https://github.com/drhenner/ror_ecommerce/blob/d4a00efaa87bc7311adf5e89f5876ae6abcf8626/app/models/variant.rb#L189

in order to avoid the unnecessary order by primary key operation

drhenner commented 7 years ago

👍

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 commented 7 years ago

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