Skip to content

Commit

Permalink
FIXES: n+1 query problem
Browse files Browse the repository at this point in the history
  • Loading branch information
wayungi committed Nov 18, 2022
1 parent 1a12c76 commit 44a26d3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/general_shopping_list_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def index

def missing_foods(recipe, inventory)
shopping_list = []
recipe_foods = recipe.recipe_foods
recipe_foods = recipe.recipe_foods.includes(:food)
if recipe_foods.length.positive?
recipe_foods.each do |recipe_food|
food = recipe_food.food
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/inventories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def index

# GET /inventories/1 or /inventories/1.json
def show
@inventory_foods = @inventory.inventory_foods.includes(:food) # , :inventory
@inventory_foods = @inventory.inventory_foods.includes(:food, :inventory)
end

# GET /inventories/new
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index

# GET public recipes
def public_recipes
@recipes = Recipe.includes(:user).order(created_at: :desc).select(&:public)
@recipes = Recipe.order(created_at: :desc).select(&:public)
end

# GET /recipes/1 or /recipes/1.json
Expand Down

0 comments on commit 44a26d3

Please sign in to comment.