Uncaching some parts and adding specs

This commit is contained in:
Will Marshall
2014-07-10 14:49:21 +10:00
parent f57e8513d5
commit 26e8a1fd91
4 changed files with 59 additions and 16 deletions

View File

@@ -9,15 +9,17 @@ class ShopController < BaseController
def products
# Can we make this query less slow?
unless @products = current_order_cycle.andand
#
if @products = current_order_cycle.andand
.valid_products_distributed_by(current_distributor).andand
.select { |p| !p.deleted? && p.has_stock_for_distribution?(current_order_cycle, current_distributor) }.andand
.sort_by {|p| p.name }
render status: 200,
json: ActiveModel::ArraySerializer.new(@products, each_serializer: Api::ProductSerializer,
current_order_cycle: current_order_cycle, current_distributor: current_distributor).to_json
else
render json: "", status: 404
end
render status: 200,
json: ActiveModel::ArraySerializer.new(@products, each_serializer: Api::ProductSerializer,
current_order_cycle: current_order_cycle, current_distributor: current_distributor).to_json
end
def order_cycle