Remove unnecessary uniq calls

The code `where(id: ids)` is equivalent to `where(id: ids.uniq)`.

Since Rails 5 uses `distinct` instead of `uniq` and in most cases where
we use `uniq` with `pluck` we should simply remove the `uniq` call (as
done in this commit), we're also removing the `Rails/UniqBeforePluck`
rubocop rule.
This commit is contained in:
Javi Martín
2019-06-23 00:28:02 +02:00
parent 9fb1d7df31
commit d639cd587a
4 changed files with 8 additions and 11 deletions

View File

@@ -93,9 +93,6 @@ Rails/SaveBang:
Rails/SkipsModelValidations:
Enabled: true
Rails/UniqBeforePluck:
Enabled: true
RSpec/AlignLeftLetBrace:
Enabled: false

View File

@@ -25,7 +25,7 @@ module ModerateActions
@resources.accessible_by(current_ability, :ignore_flag).each(&:ignore_flag)
elsif params[:block_authors].present?
author_ids = @resources.pluck(author_id).uniq
author_ids = @resources.pluck(author_id)
User.where(id: author_ids).accessible_by(current_ability, :block).each { |user| block_user user }
end

View File

@@ -48,7 +48,7 @@ class Tracking::BudgetInvestmentsController < Tracking::BaseController
def heading_filters
investments = @budget.investments.by_tracker(current_user.tracker&.id).distinct
investment_headings = Budget::Heading.where(id: investments.pluck(:heading_id).uniq)
investment_headings = Budget::Heading.where(id: investments.pluck(:heading_id))
.order(name: :asc)
all_headings_filter = [
{

View File

@@ -18,29 +18,29 @@ class UserSegments
end
def self.all_proposal_authors
author_ids(Proposal.pluck(:author_id).uniq)
author_ids(Proposal.pluck(:author_id))
end
def self.proposal_authors
author_ids(Proposal.not_archived.not_retired.pluck(:author_id).uniq)
author_ids(Proposal.not_archived.not_retired.pluck(:author_id))
end
def self.investment_authors
author_ids(current_budget_investments.pluck(:author_id).uniq)
author_ids(current_budget_investments.pluck(:author_id))
end
def self.feasible_and_undecided_investment_authors
unfeasible_and_finished_condition = "feasibility = 'unfeasible' and valuation_finished = true"
investments = current_budget_investments.where.not(unfeasible_and_finished_condition)
author_ids(investments.pluck(:author_id).uniq)
author_ids(investments.pluck(:author_id))
end
def self.selected_investment_authors
author_ids(current_budget_investments.selected.pluck(:author_id).uniq)
author_ids(current_budget_investments.selected.pluck(:author_id))
end
def self.winner_investment_authors
author_ids(current_budget_investments.winners.pluck(:author_id).uniq)
author_ids(current_budget_investments.winners.pluck(:author_id))
end
def self.not_supported_on_current_budget