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 Jan 3, 2022
1 parent eb12616 commit ca6b097
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 @@ -152,7 +152,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 @@ -165,7 +164,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 @@ -207,7 +205,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 @@ -220,7 +217,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 @@ -262,7 +258,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 @@ -274,7 +269,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 @@ -316,7 +310,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 @@ -329,7 +322,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 @@ -382,7 +374,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 @@ -405,7 +396,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 @@ -439,7 +429,6 @@

context "has LIMIT" do
it "registers an offense" do
# FIXME: duplicate offense messages
expect_offense(<<~RUBY)
courses = db.xquery(
"SELECT `courses`.*" \\
Expand All @@ -451,7 +440,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 @@ -471,7 +459,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 @@ -483,7 +470,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 ca6b097

Please sign in to comment.