mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Fixed a couple slow queries
This commit is contained in:
@@ -15,6 +15,10 @@ class ApiController < ApplicationController
|
|||||||
|
|
||||||
def tournament
|
def tournament
|
||||||
@tournament = Tournament.where(:id => params[:tournament]).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first
|
@tournament = Tournament.where(:id => params[:tournament]).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first
|
||||||
|
@schools = @tournament.schools.includes(:wrestlers)
|
||||||
|
@weights = @tournament.weights.includes(:wrestlers)
|
||||||
|
@matches = @tournament.matches.includes(:wrestlers,:schools)
|
||||||
|
@mats = @tournament.mats.includes(:matches)
|
||||||
end
|
end
|
||||||
|
|
||||||
def newTournament
|
def newTournament
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ class SchoolsController < ApplicationController
|
|||||||
# GET /schools/1.json
|
# GET /schools/1.json
|
||||||
def show
|
def show
|
||||||
session.delete(:return_path)
|
session.delete(:return_path)
|
||||||
@wrestlers = @school.wrestlers.includes(:deductedPoints,:matches,:weight)
|
@wrestlers = @school.wrestlers.includes(:deductedPoints,:matches,:weight,:school)
|
||||||
@tournament = @school.tournament
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /schools/new
|
# GET /schools/new
|
||||||
|
|||||||
@@ -174,12 +174,14 @@ class TournamentsController < ApplicationController
|
|||||||
def all_brackets
|
def all_brackets
|
||||||
@schools = @tournament.schools
|
@schools = @tournament.schools
|
||||||
@schools = @schools.sort_by{|s| s.page_score_string}.reverse!
|
@schools = @schools.sort_by{|s| s.page_score_string}.reverse!
|
||||||
|
@matches = @tournament.matches.includes(:wrestlers,:schools)
|
||||||
|
@weights = @tournament.weights.includes(:matches,:wrestlers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def bracket
|
def bracket
|
||||||
if params[:weight]
|
if params[:weight]
|
||||||
@weight = Weight.where(:id => params[:weight]).includes(:matches,:wrestlers).first
|
@weight = Weight.where(:id => params[:weight]).includes(:matches,:wrestlers).first
|
||||||
@matches = @weight.matches
|
@matches = @weight.matches.includes(:schools,:wrestlers)
|
||||||
@wrestlers = @weight.wrestlers.includes(:school)
|
@wrestlers = @weight.wrestlers.includes(:school)
|
||||||
if @tournament.tournament_type == "Pool to bracket"
|
if @tournament.tournament_type == "Pool to bracket"
|
||||||
@pools = @weight.pool_rounds(@matches)
|
@pools = @weight.pool_rounds(@matches)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Weight < ActiveRecord::Base
|
|||||||
# passed via layouts/_tournament-navbar.html.erb
|
# passed via layouts/_tournament-navbar.html.erb
|
||||||
# tournaments controller does a .split(',') on this string and creates an array via commas
|
# tournaments controller does a .split(',') on this string and creates an array via commas
|
||||||
# tournament model runs the code via method create_pre_defined_weights
|
# tournament model runs the code via method create_pre_defined_weights
|
||||||
HS_WEIGHT_CLASSES = "106,113,120,126,132,138,144,150,157,165,175,190,215,285."
|
HS_WEIGHT_CLASSES = "106,113,120,126,132,138,144,150,157,165,175,190,215,285"
|
||||||
HS_GIRLS_WEIGHT_CLASSES = "100,105,110,115,120,125,130,135,140,145,155,170,190,235"
|
HS_GIRLS_WEIGHT_CLASSES = "100,105,110,115,120,125,130,135,140,145,155,170,190,235"
|
||||||
|
|
||||||
before_destroy do
|
before_destroy do
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ json.cache! ["api_tournament", @tournament] do
|
|||||||
json.content(@tournament)
|
json.content(@tournament)
|
||||||
json.(@tournament, :id, :name, :address, :director, :director_email, :tournament_type, :created_at, :updated_at, :user_id)
|
json.(@tournament, :id, :name, :address, :director, :director_email, :tournament_type, :created_at, :updated_at, :user_id)
|
||||||
|
|
||||||
json.schools @tournament.schools do |school|
|
json.schools @schools do |school|
|
||||||
json.id school.id
|
json.id school.id
|
||||||
json.name school.name
|
json.name school.name
|
||||||
json.score school.score
|
json.score school.score
|
||||||
end
|
end
|
||||||
|
|
||||||
json.weights @tournament.weights do |weight|
|
json.weights @weights do |weight|
|
||||||
json.id weight.id
|
json.id weight.id
|
||||||
json.max weight.max
|
json.max weight.max
|
||||||
json.bracket_size weight.bracket_size
|
json.bracket_size weight.bracket_size
|
||||||
@@ -26,7 +26,7 @@ json.cache! ["api_tournament", @tournament] do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
json.mats @tournament.mats do |mat|
|
json.mats @mats do |mat|
|
||||||
json.name mat.name
|
json.name mat.name
|
||||||
json.unfinished_matches mat.unfinished_matches do |match|
|
json.unfinished_matches mat.unfinished_matches do |match|
|
||||||
json.bout_number match.bout_number
|
json.bout_number match.bout_number
|
||||||
@@ -35,7 +35,7 @@ json.cache! ["api_tournament", @tournament] do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
json.unassignedMatches @tournament.matches.select{|m| m.mat_id == nil}.sort_by{|m| m.bout_number}[0...9] do |match|
|
json.unassignedMatches @matches.select{|m| m.mat_id == nil}.sort_by{|m| m.bout_number}[0...9] do |match|
|
||||||
json.bout_number match.bout_number
|
json.bout_number match.bout_number
|
||||||
json.w1_name match.w1_name
|
json.w1_name match.w1_name
|
||||||
json.w2_name match.w2_name
|
json.w2_name match.w2_name
|
||||||
@@ -43,7 +43,7 @@ json.cache! ["api_tournament", @tournament] do
|
|||||||
json.round match.round
|
json.round match.round
|
||||||
end
|
end
|
||||||
|
|
||||||
json.matches @tournament.matches do |match|
|
json.matches @matches do |match|
|
||||||
json.bout_number match.bout_number
|
json.bout_number match.bout_number
|
||||||
json.w1_name match.w1_name
|
json.w1_name match.w1_name
|
||||||
json.w2_name match.w2_name
|
json.w2_name match.w2_name
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<% cache ["#{@tournament.id}_all_brackets", @tournament] do %>
|
<% cache ["#{@tournament.id}_all_brackets", @tournament] do %>
|
||||||
<div id="exportable" >
|
<div id="exportable" >
|
||||||
<%= render :template => 'tournaments/team_scores' %>
|
<%= render :template => 'tournaments/team_scores' %>
|
||||||
<% @tournament.weights.sort_by{|w| w.max}.each do |weight| %>
|
<% @weights.sort_by{|w| w.max}.each do |weight| %>
|
||||||
<table class='pagebreak'>
|
<table class='pagebreak'>
|
||||||
<tr>
|
<tr>
|
||||||
<% if @tournament.tournament_type == "Pool to bracket" %>
|
<% if @tournament.tournament_type == "Pool to bracket" %>
|
||||||
|
|||||||
Reference in New Issue
Block a user