Skip to content

Commit

Permalink
Merge branch 'rubocop:master' into support-new-enum-syntax-for-enum-h…
Browse files Browse the repository at this point in the history
…ash-cop
  • Loading branch information
ytjmt authored Jul 13, 2024
2 parents c6b9503 + 3e91c03 commit 05b70bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
25 changes: 17 additions & 8 deletions lib/rubocop/cop/rails/pluck_in_where.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@ module Rails
# and can be replaced with `select`.
#
# Since `pluck` is an eager method and hits the database immediately,
# using `select` helps to avoid additional database queries.
# using `select` helps to avoid additional database queries by running as
# a subquery.
#
# This cop has two different enforcement modes. When the `EnforcedStyle`
# is `conservative` (the default) then only calls to `pluck` on a constant
# (i.e. a model class) in the `where` is used as offenses.
# This cop has two modes of enforcement. When the `EnforcedStyle` is set
# to `conservative` (the default), only calls to `pluck` on a constant
# (e.g. a model class) within `where` are considered offenses.
#
# @safety
# When the `EnforcedStyle` is `aggressive` then all calls to `pluck` in the
# `where` is used as offenses. This may lead to false positives
# as the cop cannot replace to `select` between calls to `pluck` on an
# `ActiveRecord::Relation` instance vs a call to `pluck` on an `Array` instance.
# When `EnforcedStyle` is set to `aggressive`, all calls to `pluck`
# within `where` are considered offenses. This might lead to false
# positives because the check cannot distinguish between calls to
# `pluck` on an `ActiveRecord::Relation` instance and calls to `pluck`
# on an `Array` instance.
#
# Additionally, when using a subquery with the SQL `IN` operator,
# databases like PostgreSQL and MySQL can't optimize complex queries as
# well. They need to scan all records of the outer table against the
# subquery result sequentially, rather than using an index. This can
# cause significant performance issues compared to writing the query
# differently or using `pluck`.
#
# @example
# # bad
Expand Down
8 changes: 4 additions & 4 deletions rubocop-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ Gem::Specification.new do |s|
'rubygems_mfa_required' => 'true'
}

s.add_runtime_dependency 'activesupport', '>= 4.2.0'
s.add_dependency 'activesupport', '>= 4.2.0'
# Rack::Utils::SYMBOL_TO_STATUS_CODE, which is used by HttpStatus cop, was
# introduced in rack 1.1
s.add_runtime_dependency 'rack', '>= 1.1'
s.add_runtime_dependency 'rubocop', '>= 1.33.0', '< 2.0'
s.add_runtime_dependency 'rubocop-ast', '>= 1.31.1', '< 2.0'
s.add_dependency 'rack', '>= 1.1'
s.add_dependency 'rubocop', '>= 1.33.0', '< 2.0'
s.add_dependency 'rubocop-ast', '>= 1.31.1', '< 2.0'
end

0 comments on commit 05b70bb

Please sign in to comment.