Open lelelelemon opened 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.
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
https://github.com/drhenner/ror_ecommerce/blob/d4a00efaa87bc7311adf5e89f5876ae6abcf8626/app/models/variant.rb#L189
in order to avoid the unnecessary order by primary key operation