From 1bf4e6fa56f2f3862daecfb4ecd9350024410a10 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 14 Nov 2021 12:41:14 +0000 Subject: [PATCH] Reorder conditions for performance A little micro-optimisation: `@order.checkout_allowed?` requires a database query, whereas `@order.completed?` does not. So in cases where the order is completed we can return early here before hitting the database. --- app/controllers/checkout_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 6c22089cb4..cc7ba97144 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -89,9 +89,7 @@ class CheckoutController < ::BaseController end def order_invalid_for_checkout? - !@order || - !@order.checkout_allowed? || - @order.completed? + !@order || @order.completed? || !@order.checkout_allowed? end def valid_order_line_items?