From 0e5dabac8a3b9930fae86195a98d07d55238168e Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 17 Mar 2015 09:26:30 -0400 Subject: [PATCH 1/4] Moved generateMatches to tournament. Trying to reduce queries and speed up page load. --- app/models/tournament.rb | 19 ++++++++++++++++++- app/models/weight.rb | 15 --------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 6dff6ff..ea79a6b 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -3,6 +3,7 @@ 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 @@ -11,8 +12,9 @@ class Tournament < ActiveRecord::Base def upcomingMatches @matches = [] + @wrestlers = self.wrestlers self.weights.sort_by{|x|[x.max]}.each do |weight| - @upcomingMatches = weight.generateMatchups(@matches) + @upcomingMatches = generateMatchups(@matches,@wrestlers,weight) end @upcomingMatches = assignBouts(@upcomingMatches) return @upcomingMatches @@ -34,6 +36,21 @@ 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 diff --git a/app/models/weight.rb b/app/models/weight.rb index d3bae91..5c0953d 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -99,20 +99,5 @@ 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 From e3a1323d39ba484909d09289795a4eef76ef6f00 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 17 Mar 2015 09:32:11 -0400 Subject: [PATCH 2/4] Still trying to generate matches from tournament. --- app/models/tournament.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/tournament.rb b/app/models/tournament.rb index ea79a6b..808a20b 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -15,6 +15,7 @@ class Tournament < ActiveRecord::Base @wrestlers = self.wrestlers self.weights.sort_by{|x|[x.max]}.each do |weight| @upcomingMatches = generateMatchups(@matches,@wrestlers,weight) + @matches = @upcomingMatches end @upcomingMatches = assignBouts(@upcomingMatches) return @upcomingMatches From 662a1ad49881ce66fa2d08889eda3a8f49310af7 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 17 Mar 2015 09:34:36 -0400 Subject: [PATCH 3/4] Revert "Still trying to generate matches from tournament." This reverts commit e3a1323d39ba484909d09289795a4eef76ef6f00. --- app/models/tournament.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/tournament.rb b/app/models/tournament.rb index 808a20b..ea79a6b 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -15,7 +15,6 @@ class Tournament < ActiveRecord::Base @wrestlers = self.wrestlers self.weights.sort_by{|x|[x.max]}.each do |weight| @upcomingMatches = generateMatchups(@matches,@wrestlers,weight) - @matches = @upcomingMatches end @upcomingMatches = assignBouts(@upcomingMatches) return @upcomingMatches From b3b4fdb6e57dc1825d7f3f2e9b9b79e560ed858d Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 17 Mar 2015 09:34:43 -0400 Subject: [PATCH 4/4] Revert "Moved generateMatches to tournament. Trying to reduce queries and speed" This reverts commit 0e5dabac8a3b9930fae86195a98d07d55238168e. --- app/models/tournament.rb | 19 +------------------ app/models/weight.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/models/tournament.rb b/app/models/tournament.rb index ea79a6b..6dff6ff 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -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 diff --git a/app/models/weight.rb b/app/models/weight.rb index 5c0953d..d3bae91 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -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