From 750b2f915bdf0cc21928196ed8c6de2cec085f87 Mon Sep 17 00:00:00 2001 From: Eric Stiens Date: Mon, 14 Nov 2022 16:06:29 -0600 Subject: [PATCH] fixup typo in group parsing setup task --- config/puma.rb | 4 ++-- lib/2022/setup.rb | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/config/puma.rb b/config/puma.rb index c4269c8..5b8d9fc 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,7 +1,7 @@ if Rails.env.production? workers Integer(ENV['WEB_CONCURRENCY'] || 3) - min_threads = Integer(ENV['MIN_THREADS'] || ENV['RAILS_MAX_THREADS'] || 8) - max_threads = Integer(ENV['RAILS_MAX_THREADS'] || 32) + min_threads = Integer(ENV['MIN_THREADS'] || ENV['RAILS_MAX_THREADS'] || 4) + max_threads = Integer(ENV['RAILS_MAX_THREADS'] || 8) threads min_threads, max_threads else diff --git a/lib/2022/setup.rb b/lib/2022/setup.rb index 1656c51..2480e52 100644 --- a/lib/2022/setup.rb +++ b/lib/2022/setup.rb @@ -13,22 +13,29 @@ def self.setup_teams end end + def self.create_groups + %w[A B C D E F G H].each do |letter| + Group.find_or_create_by(letter: letter) + end + end + def self.parse_groups + create_groups unless Group.count == 8 group_json = File.read(Rails.root.join('lib/assets/wc2022/groups.json')) JSON.parse(group_json) end def self.setup_groups - parse_groups.each do |g| - group = Group.find_or_create_by(letter: g.first[0]) - group.teams = [] - g.first[1].each do |name| + parse_groups.each do |data| + teams = data.first.last + group = Group.find_by(letter: data.first[0]) + teams.each do |name| team = Team.find_by(alternate_name: name) || Team.find_by(country: name) raise "Could not find team for #{name}" unless team + next if group.teams.include? team - group.teams << team + team.update!(group: group) end - group.save end end end