mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-11 16:01:56 +00:00
Moved generateMatches to tournament. Trying to reduce queries and speed
up page load.
This commit is contained in:
@@ -3,6 +3,7 @@ class Tournament < ActiveRecord::Base
|
|||||||
has_many :weights, dependent: :destroy
|
has_many :weights, dependent: :destroy
|
||||||
has_many :matches, dependent: :destroy
|
has_many :matches, dependent: :destroy
|
||||||
has_many :mats, dependent: :destroy
|
has_many :mats, dependent: :destroy
|
||||||
|
has_many :wrestlers, through: :weights
|
||||||
attr_accessor :upcomingMatches, :unfinishedMatches
|
attr_accessor :upcomingMatches, :unfinishedMatches
|
||||||
|
|
||||||
def self.unfinishedMatches
|
def self.unfinishedMatches
|
||||||
@@ -11,8 +12,9 @@ class Tournament < ActiveRecord::Base
|
|||||||
|
|
||||||
def upcomingMatches
|
def upcomingMatches
|
||||||
@matches = []
|
@matches = []
|
||||||
|
@wrestlers = self.wrestlers
|
||||||
self.weights.sort_by{|x|[x.max]}.each do |weight|
|
self.weights.sort_by{|x|[x.max]}.each do |weight|
|
||||||
@upcomingMatches = weight.generateMatchups(@matches)
|
@upcomingMatches = generateMatchups(@matches,@wrestlers,weight)
|
||||||
end
|
end
|
||||||
@upcomingMatches = assignBouts(@upcomingMatches)
|
@upcomingMatches = assignBouts(@upcomingMatches)
|
||||||
return @upcomingMatches
|
return @upcomingMatches
|
||||||
@@ -34,6 +36,21 @@ class Tournament < ActiveRecord::Base
|
|||||||
return @matches
|
return @matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generateMatchups(matches,wrestlers,weight)
|
||||||
|
@wrestlers = wrestlers.select{|w| w.weight_id == weight.id}
|
||||||
|
if weight.pools == 1
|
||||||
|
@pool = Pool.new
|
||||||
|
@matches = @pool.generatePools(1,@wrestlers,weight,self.id,matches)
|
||||||
|
elsif weight.pools == 2
|
||||||
|
@pool = Pool.new
|
||||||
|
@matches = @pool.generatePools(2,@wrestlers,weight,self.id,matches)
|
||||||
|
elsif weight.pools == 4
|
||||||
|
@pool = Pool.new
|
||||||
|
@matches = @pool.generatePools(4,@wrestlers,weight,self.id,matches)
|
||||||
|
end
|
||||||
|
return @matches
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -100,19 +100,4 @@ class Weight < ActiveRecord::Base
|
|||||||
self.wrestlers.size
|
self.wrestlers.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def generateMatchups(matches)
|
|
||||||
@wrestlers = self.wrestlers
|
|
||||||
if self.pools == 1
|
|
||||||
@pool = Pool.new
|
|
||||||
@matches = @pool.generatePools(1,@wrestlers,self,self.tournament_id,matches)
|
|
||||||
elsif self.pools == 2
|
|
||||||
@pool = Pool.new
|
|
||||||
@matches = @pool.generatePools(2,@wrestlers,self,self.tournament_id,matches)
|
|
||||||
elsif self.pools == 4
|
|
||||||
@pool = Pool.new
|
|
||||||
@matches = @pool.generatePools(4,@wrestlers,self,self.tournament_id,matches)
|
|
||||||
end
|
|
||||||
return @matches
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user