mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-05 22:21:26 +00:00
Trying to increase speed of up_matches
This commit is contained in:
@@ -2,15 +2,15 @@ class StaticPagesController < ApplicationController
|
|||||||
before_filter :check_access, only: [:createCustomWeights,:generate_matches,:weigh_in]
|
before_filter :check_access, only: [:createCustomWeights,:generate_matches,:weigh_in]
|
||||||
|
|
||||||
def tournaments
|
def tournaments
|
||||||
@tournaments = Tournament.all.includes(:user)
|
@tournaments = Tournament.all.includes(:user,:matches,:mats)
|
||||||
end
|
end
|
||||||
def up_matches
|
def up_matches
|
||||||
if params[:tournament]
|
if params[:tournament]
|
||||||
@tournament = Tournament.find(params[:tournament])
|
@tournament = Tournament.find(params[:tournament])
|
||||||
end
|
end
|
||||||
if @tournament
|
if @tournament
|
||||||
@matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10)
|
@matches = @tournament.matches.where(mat_id: nil).order('bout_number ASC').limit(10).includes(:wrestlers)
|
||||||
@mats = @tournament.mats
|
@mats = @tournament.mats.includes(:matches)
|
||||||
if @tournament.matches.empty?
|
if @tournament.matches.empty?
|
||||||
redirect_to "/static_pages/noMatches?tournament=#{@tournament.id}"
|
redirect_to "/static_pages/noMatches?tournament=#{@tournament.id}"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ class Match < ActiveRecord::Base
|
|||||||
belongs_to :tournament
|
belongs_to :tournament
|
||||||
belongs_to :weight
|
belongs_to :weight
|
||||||
belongs_to :mat
|
belongs_to :mat
|
||||||
|
has_many :wrestlers, :through => :weight
|
||||||
|
|
||||||
after_save do
|
after_save do
|
||||||
if self.finished == 1
|
if self.finished == 1
|
||||||
@@ -30,6 +31,14 @@ class Match < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def wrestler1
|
||||||
|
wrestlers.where(id: self.w1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def wrestler2
|
||||||
|
wrestlers.where(id: self.w2)
|
||||||
|
end
|
||||||
|
|
||||||
def w1_name
|
def w1_name
|
||||||
if self.w1
|
if self.w1
|
||||||
Wrestler.find(self.w1).name
|
Wrestler.find(self.w1).name
|
||||||
|
|||||||
@@ -30,10 +30,10 @@
|
|||||||
<% @mats.each.map do |m| %>
|
<% @mats.each.map do |m| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= m.name %></td>
|
<td><%= m.name %></td>
|
||||||
<td><%=m.unfinishedMatches.first.bout_number%><br><%= m.unfinishedMatches.first.w1_name %> vs. <%= m.unfinishedMatches.first.w2_name %></td>
|
<td><%=m.unfinishedMatches.first.bout_number%><br><%= m.unfinishedMatches.first.wrestler1.name %> vs. <%= m.unfinishedMatches.first.wrestler2.name %></td>
|
||||||
<td><%=m.unfinishedMatches.second.bout_number%><br><%= m.unfinishedMatches.second.w1_name %> vs. <%= m.unfinishedMatches.second.w2_name %></td>
|
<td><%=m.unfinishedMatches.second.bout_number%><br><%= m.unfinishedMatches.second.wrestler1.name %> vs. <%= m.unfinishedMatches.second.wrestler2.name %></td>
|
||||||
<td><%=m.unfinishedMatches.third.bout_number%><br><%= m.unfinishedMatches.third.w1_name %> vs. <%= m.unfinishedMatches.third.w2_name %></td>
|
<td><%=m.unfinishedMatches.third.bout_number%><br><%= m.unfinishedMatches.third.wrestler1.name %> vs. <%= m.unfinishedMatches.third.wrestler2.name %></td>
|
||||||
<td><%=m.unfinishedMatches.fourth.bout_number%><br><%= m.unfinishedMatches.fourth.w1_name %> vs. <%= m.unfinishedMatches.fourth.w2_name %></td>
|
<td><%=m.unfinishedMatches.fourth.bout_number%><br><%= m.unfinishedMatches.fourth.wrestler1.name %> vs. <%= m.unfinishedMatches.fourth.wrestler2.name %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<td>Round <%= m.round %></td>
|
<td>Round <%= m.round %></td>
|
||||||
<td><%= m.bout_number %></td>
|
<td><%= m.bout_number %></td>
|
||||||
<td><%= m.weight_max %> lbs</td>
|
<td><%= m.weight_max %> lbs</td>
|
||||||
<td><%= m.w1_name %> vs. <%= m.w2_name %></td>
|
<td><%= m.wrestler1.name %> vs. <%= m.wrestler2.name %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user