From eb7de1829869b11bd64a5ca0cb5d90230f1a0f62 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 28 Apr 2020 13:51:25 +0200 Subject: [PATCH] Return early (before hitting the DB) in complex product list rendering if we already know the order cycle is closed --- app/controllers/api/order_cycles_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/order_cycles_controller.rb b/app/controllers/api/order_cycles_controller.rb index d4ce2cdc7b..b06f302169 100644 --- a/app/controllers/api/order_cycles_controller.rb +++ b/app/controllers/api/order_cycles_controller.rb @@ -6,6 +6,8 @@ module Api skip_authorization_check def products + render_no_products unless order_cycle.open? + products = ProductsRenderer.new( distributor, order_cycle, @@ -15,7 +17,7 @@ module Api render json: products rescue ProductsRenderer::NoProducts - render status: :not_found, json: '' + render_no_products end def taxons @@ -35,6 +37,10 @@ module Api private + def render_no_products + render status: :not_found, json: '' + end + def product_properties Spree::Property. joins(:products).