1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-10 15:50:50 +00:00

Using eager loading in GenerateTournamentMatches and AdvanceWrestler, generating/manipulating in-memory, and doing a single bulk insert or update at the end.

This commit is contained in:
2026-02-24 20:58:36 -05:00
parent ca4d5ce0db
commit 18d39c6c8f
18 changed files with 904 additions and 521 deletions

View File

@@ -1,35 +1,46 @@
class PoolGeneration
def initialize(weight)
def initialize(weight, wrestlers: nil)
@weight = weight
@tournament = @weight.tournament
@pool = 1
@wrestlers = wrestlers
end
def generatePools
GeneratePoolNumbers.new(@weight).savePoolNumbers
GeneratePoolNumbers.new(@weight).savePoolNumbers(wrestlers: wrestlers_for_weight, persist: false)
rows = []
pools = @weight.pools
while @pool <= pools
roundRobin
rows.concat(roundRobin)
@pool += 1
end
rows
end
def roundRobin
wrestlers = @weight.wrestlers_in_pool(@pool)
rows = []
wrestlers = wrestlers_for_weight.select { |w| w.pool == @pool }
pool_matches = RoundRobinTournament.schedule(wrestlers).reverse
pool_matches.each_with_index do |b, index|
round = index + 1
bouts = b.map
bouts.each do |bout|
if bout[0] != nil and bout[1] != nil
@tournament.matches.create(
rows << {
w1: bout[0].id,
w2: bout[1].id,
tournament_id: @tournament.id,
weight_id: @weight.id,
bracket_position: "Pool",
round: round)
round: round
}
end
end
end
rows
end
def wrestlers_for_weight
@wrestlers || @weight.wrestlers.to_a
end
end