1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

Revert "Moved generateMatches to tournament. Trying to reduce queries and speed"

This reverts commit 0e5dabac8a.
This commit is contained in:
2015-03-17 09:34:43 -04:00
parent 662a1ad498
commit b3b4fdb6e5
2 changed files with 16 additions and 18 deletions

View File

@@ -3,7 +3,6 @@ class Tournament < ActiveRecord::Base
has_many :weights, dependent: :destroy
has_many :matches, dependent: :destroy
has_many :mats, dependent: :destroy
has_many :wrestlers, through: :weights
attr_accessor :upcomingMatches, :unfinishedMatches
def self.unfinishedMatches
@@ -12,9 +11,8 @@ class Tournament < ActiveRecord::Base
def upcomingMatches
@matches = []
@wrestlers = self.wrestlers
self.weights.sort_by{|x|[x.max]}.each do |weight|
@upcomingMatches = generateMatchups(@matches,@wrestlers,weight)
@upcomingMatches = weight.generateMatchups(@matches)
end
@upcomingMatches = assignBouts(@upcomingMatches)
return @upcomingMatches
@@ -36,21 +34,6 @@ class Tournament < ActiveRecord::Base
return @matches
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

View File

@@ -99,5 +99,20 @@ class Weight < ActiveRecord::Base
end
self.wrestlers.size
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