From 183ca46fa4bae16314b0675130879e2c50e3b240 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 3 Nov 2015 12:04:58 -0500 Subject: [PATCH] Fix N+1 on API --- app/controllers/api/v1/cards_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/cards_controller.rb b/app/controllers/api/v1/cards_controller.rb index 9397780..7b04385 100644 --- a/app/controllers/api/v1/cards_controller.rb +++ b/app/controllers/api/v1/cards_controller.rb @@ -1,7 +1,12 @@ class Api::V1::CardsController < Api::V1::BaseController before_action :set_card, only: [:show] def index - render json: Card.all, root: false + @cards = Card.includes(:character, :rarity, :type, :leader_skill, + :passive_skill, :super_attack, :awaken_type, + :dokkan_card, :hp_stat, :atk_stat, :def_stat, + :links) + + render json: @cards, root: false end def show