From 85dfadf8d2a0a5d3bc81c049bec8a646fedb7291 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Mon, 2 Nov 2015 11:31:40 -0500 Subject: [PATCH] Reducing queries on up_matches and brackets --- app/controllers/static_pages_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index a0ea95e..d16a3e2 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -6,7 +6,7 @@ class StaticPagesController < ApplicationController end def up_matches if params[:tournament] - @tournament = Tournament.find(params[:tournament]) + @tournament = Tournament.where(:id => params[:tournament]).includes(:matches).first end if @tournament @matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers) @@ -39,8 +39,8 @@ class StaticPagesController < ApplicationController def brackets if params[:weight] - @weight = Weight.find(params[:weight]).includes(:matches,:wrestlers) - @tournament = Tournament.find(@weight.tournament_id) + @weight = Weight.where(:id => params[:weight]).includes(:matches,:wrestlers,:tournament).first + @tournament = @weight.tournament @matches = @weight.matches @wrestlers = @weight.wrestlers.includes(:school) if @matches.empty? or @wrestlers.empty?