From 3fbdc9253d395efb020b7e20d65faf7cde02a7b1 Mon Sep 17 00:00:00 2001 From: camdenmoors Date: Fri, 19 Jun 2020 15:19:55 -0400 Subject: [PATCH 1/8] Configure bullet --- Gemfile | 1 + Gemfile.lock | 5 +++++ config/environments/development.rb | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/Gemfile b/Gemfile index 9200593a..5025a6de 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,7 @@ gem 'awesome_nested_fields' gem 'bootsnap', '>= 1.1.0', require: false gem 'bootstrap-kaminari-views' gem 'bootstrap-sass', '~> 2.3.2.2' +gem "bullet" gem 'carrierwave-postgresql', '< 0.3.0' # Can be upgraded once https://github.com/diogob/carrierwave-postgresql/issues/33 gem 'chartkick' gem 'delayed_job' diff --git a/Gemfile.lock b/Gemfile.lock index af9d4e2d..06922d78 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,6 +77,9 @@ GEM sass (~> 3.2) brakeman (4.8.2) builder (3.2.4) + bullet (6.1.0) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.11) bundler-audit (0.7.0.1) bundler (>= 1.2.0, < 3) thor (>= 0.18, < 2) @@ -354,6 +357,7 @@ GEM uglifier (4.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (1.7.0) + uniform_notifier (1.13.0) warden (1.2.8) rack (>= 2.0.6) websocket-driver (0.7.2) @@ -371,6 +375,7 @@ DEPENDENCIES bootstrap-kaminari-views bootstrap-sass (~> 2.3.2.2) brakeman + bullet bundler-audit carrierwave-postgresql (< 0.3.0) chartkick diff --git a/config/environments/development.rb b/config/environments/development.rb index ba48a3d5..4695475c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -67,4 +67,8 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + end end From 576be584397b065277191b754762ffb711a30357 Mon Sep 17 00:00:00 2001 From: camdenmoors Date: Fri, 19 Jun 2020 15:45:34 -0400 Subject: [PATCH 2/8] Remove includes, it's not needed --- app/models/division.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/division.rb b/app/models/division.rb index 4c8b5524..76771ec2 100644 --- a/app/models/division.rb +++ b/app/models/division.rb @@ -71,7 +71,7 @@ def calculate_pentest_solved_challenge_score # This calculates the teams score for all point-based challenges (StandardSolvedChallenges and ScoreAdjustments) # This does not calculate the score for PentestChallenges def calculate_standard_solved_challenge_score - teams.includes(:achievements).joins( + teams.joins( "LEFT JOIN feed_items AS point_feed_items ON point_feed_items.team_id = teams.id AND point_feed_items.type IN ('StandardSolvedChallenge', 'ScoreAdjustment') From cf44729b4584698ca61bb8d2b9af78fdd04f19ad Mon Sep 17 00:00:00 2001 From: camdenmoors Date: Fri, 19 Jun 2020 15:55:43 -0400 Subject: [PATCH 3/8] Use single-quotes on gemfile --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 5025a6de..1d6704c6 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ gem 'awesome_nested_fields' gem 'bootsnap', '>= 1.1.0', require: false gem 'bootstrap-kaminari-views' gem 'bootstrap-sass', '~> 2.3.2.2' -gem "bullet" +gem 'bullet' gem 'carrierwave-postgresql', '< 0.3.0' # Can be upgraded once https://github.com/diogob/carrierwave-postgresql/issues/33 gem 'chartkick' gem 'delayed_job' From 35bae5239a233b0a0c052c385c179f5158a360da Mon Sep 17 00:00:00 2001 From: camdenmoors <66680985+camdenmoors@users.noreply.github.com> Date: Wed, 24 Jun 2020 11:08:32 -0400 Subject: [PATCH 4/8] Configure test environment to use Bullet --- config/environments/test.rb | 5 ++++ .../team_summary_display_modes_test.rb | 30 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/integration/team_summary_display_modes_test.rb diff --git a/config/environments/test.rb b/config/environments/test.rb index 76ee95de..c91702ee 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -53,4 +53,9 @@ # Set default URL for mailer to mimic production config.action_mailer.default_url_options = { host: 'test.mitrecyberacademy.org' } + + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + end end diff --git a/test/integration/team_summary_display_modes_test.rb b/test/integration/team_summary_display_modes_test.rb new file mode 100644 index 00000000..483627e0 --- /dev/null +++ b/test/integration/team_summary_display_modes_test.rb @@ -0,0 +1,30 @@ +require 'test_helper' + +class TeamSummaryDisplayModesTest < ActionDispatch::IntegrationTest + include TeamsHelper + include Devise::Test::IntegrationHelpers + + test "test bullet discovers n+1 query on summary page" do + create(:active_game, board_layout: :jeopardy) + team = create(:team) + + chal1 = create(:standard_challenge, point_value: 100, category_count: 2) + chal2 = create(:standard_challenge, point_value: 100, category_count: 0) + chal3 = create(:standard_challenge, point_value: 150, category_count: 1) + chal4 = create(:standard_challenge, point_value: 100, category_count: 0) + chal5 = create(:standard_challenge, point_value: 100, category_count: 0) + + solved_chal1 = create(:standard_solved_challenge, team: team, challenge: chal1) + solved_chal2 = create(:standard_solved_challenge, team: team, challenge: chal2) + solved_chal3 = create(:standard_solved_challenge, team: team, challenge: chal3) + solved_chal4 = create(:standard_solved_challenge, team: team, challenge: chal4) + solved_chal5 = create(:standard_solved_challenge, team: team, challenge: chal5) + + captain = team.team_captain + + sign_in captain + + get "/teams/#{team.id}/summary" + + end +end From eb81789f47c7d810524e1ce38d19b59556a53a3b Mon Sep 17 00:00:00 2001 From: camdenmoors <66680985+camdenmoors@users.noreply.github.com> Date: Wed, 24 Jun 2020 11:08:51 -0400 Subject: [PATCH 5/8] Save bullet log to as an artifact --- .github/workflows/run-tests.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 29ddd566..2326d60a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -59,3 +59,11 @@ jobs: with: name: coverage-report path: coverage + + - name: Upload bullet log + uses: actions/upload-artifact@master + if: always() + with: + name: bullet-log + path: log/bullet.log + From 8dbe922db1ca736d77721308a0d1801959a71794 Mon Sep 17 00:00:00 2001 From: camdenmoors <66680985+camdenmoors@users.noreply.github.com> Date: Wed, 24 Jun 2020 11:57:45 -0400 Subject: [PATCH 6/8] Switch upload-artifact@master to upload-artifact v2 --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 2326d60a..ae2ef356 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -61,7 +61,7 @@ jobs: path: coverage - name: Upload bullet log - uses: actions/upload-artifact@master + uses: actions/upload-artifact@v2 if: always() with: name: bullet-log From cb697f225ca1da9c9eddb428e6778f49e5080bbd Mon Sep 17 00:00:00 2001 From: camdenmoors <66680985+camdenmoors@users.noreply.github.com> Date: Wed, 24 Jun 2020 12:00:51 -0400 Subject: [PATCH 7/8] Switch upload singular file artifact to the logs folder --- .github/workflows/run-tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ae2ef356..a6a150d8 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -60,10 +60,9 @@ jobs: name: coverage-report path: coverage - - name: Upload bullet log + - name: Upload logs uses: actions/upload-artifact@v2 if: always() with: name: bullet-log - path: log/bullet.log - + path: log From 3e6dc4478dc338780c76f73c9e712fed7add7a34 Mon Sep 17 00:00:00 2001 From: camdenmoors <66680985+camdenmoors@users.noreply.github.com> Date: Wed, 24 Jun 2020 12:01:41 -0400 Subject: [PATCH 8/8] Switch back to master action --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a6a150d8..841787aa 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -61,7 +61,7 @@ jobs: path: coverage - name: Upload logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@master if: always() with: name: bullet-log