1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-04 22:03:49 +00:00

Reducing queries on up_matches and brackets

This commit is contained in:
2015-11-02 11:31:40 -05:00
parent bdfbb36d48
commit 85dfadf8d2

View File

@@ -6,7 +6,7 @@ class StaticPagesController < ApplicationController
end end
def up_matches def up_matches
if params[:tournament] if params[:tournament]
@tournament = Tournament.find(params[:tournament]) @tournament = Tournament.where(:id => params[:tournament]).includes(:matches).first
end end
if @tournament if @tournament
@matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers) @matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers)
@@ -39,8 +39,8 @@ class StaticPagesController < ApplicationController
def brackets def brackets
if params[:weight] if params[:weight]
@weight = Weight.find(params[:weight]).includes(:matches,:wrestlers) @weight = Weight.where(:id => params[:weight]).includes(:matches,:wrestlers,:tournament).first
@tournament = Tournament.find(@weight.tournament_id) @tournament = @weight.tournament
@matches = @weight.matches @matches = @weight.matches
@wrestlers = @weight.wrestlers.includes(:school) @wrestlers = @weight.wrestlers.includes(:school)
if @matches.empty? or @wrestlers.empty? if @matches.empty? or @wrestlers.empty?