Skip to content

Commit

Permalink
[WIP] Fixed. NPlusOneQuery duplicate offense
Browse files Browse the repository at this point in the history
  • Loading branch information
sue445 committed Nov 29, 2021
1 parent 3237369 commit c731bb9
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions spec/rubocop/cop/isucon/mysql2/n_plus_one_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
describe "#perform_autocorrect" do
context "Hash#[] with symbol key" do
it "registers an offense and correct" do
# FIXME: duplicate offense messages
# c.f. https://github.com/isucon/isucon11-final/blob/667be3ec70c025eadde541e21d5ab1167efa1dd3/webapp/ruby/app.rb#L171-L190
expect_offense(<<~RUBY)
courses = db.xquery(
Expand All @@ -135,7 +134,6 @@
courses.map do |course|
teacher = db.xquery('SELECT * FROM `users` WHERE `id` = ?', course[:teacher_id]).first
^^ This looks like N+1 query.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This looks like N+1 query.
raise unless teacher
Expand Down Expand Up @@ -177,7 +175,6 @@

context "Hash#[] with string key" do
it "registers an offense and correct" do
# FIXME: duplicate offense messages
# c.f. https://github.com/isucon/isucon11-final/blob/667be3ec70c025eadde541e21d5ab1167efa1dd3/webapp/ruby/app.rb#L171-L190
expect_offense(<<~RUBY)
courses = db.xquery(
Expand All @@ -190,7 +187,6 @@
courses.map do |course|
teacher = db.xquery('SELECT * FROM `users` WHERE `id` = ?', course["teacher_id"]).first
^^ This looks like N+1 query.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This looks like N+1 query.
raise unless teacher
Expand Down Expand Up @@ -232,7 +228,6 @@

context "Hash#fetch with symbol key" do
it "registers an offense and correct" do
# FIXME: duplicate offense messages
expect_offense(<<~RUBY)
courses = db.xquery(
"SELECT `courses`.*" \\
Expand All @@ -244,7 +239,6 @@
courses.map do |course|
teacher = db.xquery('SELECT * FROM `users` WHERE `id` = ?', course.fetch(:teacher_id)).first
^^ This looks like N+1 query.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This looks like N+1 query.
raise unless teacher
Expand Down Expand Up @@ -286,7 +280,6 @@

context "Hash#fetch with string key" do
it "registers an offense and correct" do
# FIXME: duplicate offense messages
# c.f. https://github.com/isucon/isucon11-final/blob/667be3ec70c025eadde541e21d5ab1167efa1dd3/webapp/ruby/app.rb#L171-L190
expect_offense(<<~RUBY)
courses = db.xquery(
Expand All @@ -299,7 +292,6 @@
courses.map do |course|
teacher = db.xquery('SELECT * FROM `users` WHERE `id` = ?', course.fetch("teacher_id")).first
^^ This looks like N+1 query.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This looks like N+1 query.
raise unless teacher
Expand Down Expand Up @@ -352,7 +344,6 @@
courses.map do |course|
teacher = db.xquery('SELECT * FROM `users` WHERE `name` = ?', course[:teacher_id]).first
^^ This looks like N+1 query.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This looks like N+1 query.
raise unless teacher
Expand All @@ -375,7 +366,6 @@
expect_offense(<<~RUBY)
courses.map do |course|
teacher = db.xquery('SELECT * FROM `users` WHERE `id` = ?', course[:teacher_id]).first
^^ This looks like N+1 query.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This looks like N+1 query.
raise unless teacher
Expand Down Expand Up @@ -409,7 +399,6 @@

context "has LIMIT" do
it "registers an offense" do
# FIXME: duplicate offense messages
expect_offense(<<~RUBY)
courses = db.xquery(
"SELECT `courses`.*" \\
Expand All @@ -421,7 +410,6 @@
courses.map do |course|
teacher = db.xquery('SELECT * FROM `users` WHERE `id` = ? LIMIT 1', course[:teacher_id]).first
^^ This looks like N+1 query.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This looks like N+1 query.
raise unless teacher
Expand All @@ -441,7 +429,6 @@

context "has GROUP BY" do
it "registers an offense" do
# FIXME: duplicate offense messages
expect_offense(<<~RUBY)
courses = db.xquery(
"SELECT `courses`.*" \\
Expand All @@ -453,7 +440,6 @@
courses.map do |course|
teacher = db.xquery('SELECT * FROM `users` WHERE `id` = ? GROUP BY name', course[:teacher_id]).first
^^ This looks like N+1 query.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This looks like N+1 query.
raise unless teacher
Expand Down

0 comments on commit c731bb9

Please sign in to comment.