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
|
||||
@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
|
||||
|
||||
def newTournament
|
||||
|
||||
@@ -12,8 +12,7 @@ class SchoolsController < ApplicationController
|
||||
# GET /schools/1.json
|
||||
def show
|
||||
session.delete(:return_path)
|
||||
@wrestlers = @school.wrestlers.includes(:deductedPoints,:matches,:weight)
|
||||
@tournament = @school.tournament
|
||||
@wrestlers = @school.wrestlers.includes(:deductedPoints,:matches,:weight,:school)
|
||||
end
|
||||
|
||||
# GET /schools/new
|
||||
|
||||
@@ -174,12 +174,14 @@ class TournamentsController < ApplicationController
|
||||
def all_brackets
|
||||
@schools = @tournament.schools
|
||||
@schools = @schools.sort_by{|s| s.page_score_string}.reverse!
|
||||
@matches = @tournament.matches.includes(:wrestlers,:schools)
|
||||
@weights = @tournament.weights.includes(:matches,:wrestlers)
|
||||
end
|
||||
|
||||
def bracket
|
||||
if params[:weight]
|
||||
@weight = Weight.where(:id => params[:weight]).includes(:matches,:wrestlers).first
|
||||
@matches = @weight.matches
|
||||
@matches = @weight.matches.includes(:schools,:wrestlers)
|
||||
@wrestlers = @weight.wrestlers.includes(:school)
|
||||
if @tournament.tournament_type == "Pool to bracket"
|
||||
@pools = @weight.pool_rounds(@matches)
|
||||
|
||||
@@ -10,7 +10,7 @@ class Weight < ActiveRecord::Base
|
||||
# passed via layouts/_tournament-navbar.html.erb
|
||||
# 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
|
||||
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"
|
||||
|
||||
before_destroy do
|
||||
|
||||
@@ -3,13 +3,13 @@ json.cache! ["api_tournament", @tournament] do
|
||||
json.content(@tournament)
|
||||
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.name school.name
|
||||
json.score school.score
|
||||
end
|
||||
|
||||
json.weights @tournament.weights do |weight|
|
||||
json.weights @weights do |weight|
|
||||
json.id weight.id
|
||||
json.max weight.max
|
||||
json.bracket_size weight.bracket_size
|
||||
@@ -26,7 +26,7 @@ json.cache! ["api_tournament", @tournament] do
|
||||
end
|
||||
end
|
||||
|
||||
json.mats @tournament.mats do |mat|
|
||||
json.mats @mats do |mat|
|
||||
json.name mat.name
|
||||
json.unfinished_matches mat.unfinished_matches do |match|
|
||||
json.bout_number match.bout_number
|
||||
@@ -35,7 +35,7 @@ json.cache! ["api_tournament", @tournament] do
|
||||
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.w1_name match.w1_name
|
||||
json.w2_name match.w2_name
|
||||
@@ -43,7 +43,7 @@ json.cache! ["api_tournament", @tournament] do
|
||||
json.round match.round
|
||||
end
|
||||
|
||||
json.matches @tournament.matches do |match|
|
||||
json.matches @matches do |match|
|
||||
json.bout_number match.bout_number
|
||||
json.w1_name match.w1_name
|
||||
json.w2_name match.w2_name
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
<% cache ["#{@tournament.id}_all_brackets", @tournament] do %>
|
||||
<div id="exportable" >
|
||||
<%= 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'>
|
||||
<tr>
|
||||
<% if @tournament.tournament_type == "Pool to bracket" %>
|
||||
|
||||
Reference in New Issue
Block a user