Commit e6adbdea authored by Kerri Miller's avatar Kerri Miller

Merge branch 'pl-rubocop-todo-count' into 'master'

Resolves rubocop offense Performance/Count

See merge request gitlab-org/gitlab!57007
parents 4badc4a8 1dadba0b
...@@ -266,19 +266,6 @@ Performance/CollectionLiteralInLoop: ...@@ -266,19 +266,6 @@ Performance/CollectionLiteralInLoop:
Performance/ConstantRegexp: Performance/ConstantRegexp:
Enabled: false Enabled: false
# Offense count: 18
# Cop supports --auto-correct.
Performance/Count:
Exclude:
- 'app/helpers/groups_helper.rb'
- 'app/services/merge_requests/add_context_service.rb'
- 'ee/lib/gitlab/graphql/aggregations/epics/epic_node.rb'
- 'lib/gitlab/sidekiq_status.rb'
- 'spec/lib/gitlab/conflict/file_spec.rb'
- 'spec/lib/gitlab/git/tree_spec.rb'
- 'spec/models/ci/build_spec.rb'
- 'spec/support_specs/helpers/active_record/query_recorder_spec.rb'
# Offense count: 14 # Offense count: 14
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: SafeMultiline. # Configuration parameters: SafeMultiline.
......
...@@ -141,9 +141,9 @@ module GroupsHelper ...@@ -141,9 +141,9 @@ module GroupsHelper
def projects_lfs_status(group) def projects_lfs_status(group)
lfs_status = lfs_status =
if group.lfs_enabled? if group.lfs_enabled?
group.projects.select(&:lfs_enabled?).size group.projects.count(&:lfs_enabled?)
else else
group.projects.reject(&:lfs_enabled?).size group.projects.count { |project| !project.lfs_enabled? }
end end
size = group.projects.size size = group.projects.size
......
...@@ -50,7 +50,7 @@ module MergeRequests ...@@ -50,7 +50,7 @@ module MergeRequests
def duplicates def duplicates
existing_oids = merge_request.merge_request_context_commits.map { |commit| commit.sha.to_s } existing_oids = merge_request.merge_request_context_commits.map { |commit| commit.sha.to_s }
existing_oids.select do |existing_oid| existing_oids.select do |existing_oid|
commit_ids.select { |commit_id| existing_oid.start_with?(commit_id) }.count > 0 commit_ids.count { |commit_id| existing_oid.start_with?(commit_id) } > 0
end end
end end
......
---
title: Resolve offense Performance/Count
merge_request: 57007
author: Shubham Kumar (@imskr)
type: fixed
...@@ -88,7 +88,7 @@ module Gitlab ...@@ -88,7 +88,7 @@ module Gitlab
# {iid: 1, epic_state_id: 1, issues_count: 1, issues_weight_sum: 2, parent_id: nil, issues_state_id: 2} # {iid: 1, epic_state_id: 1, issues_count: 1, issues_weight_sum: 2, parent_id: nil, issues_state_id: 2}
if type == EPIC_TYPE if type == EPIC_TYPE
# can only be COUNT # can only be COUNT
children.select { |node| node.epic_state_id == state }.count children.count { |node| node.epic_state_id == state }
else else
matching_record = epic_info_flat_list.find do |record| matching_record = epic_info_flat_list.find do |record|
record[:issues_state_id] == state record[:issues_state_id] == state
......
...@@ -66,7 +66,7 @@ module Gitlab ...@@ -66,7 +66,7 @@ module Gitlab
def self.num_running(job_ids) def self.num_running(job_ids)
responses = self.job_status(job_ids) responses = self.job_status(job_ids)
responses.select(&:present?).count responses.count(&:present?)
end end
# Returns the number of jobs that have completed. # Returns the number of jobs that have completed.
......
...@@ -298,12 +298,12 @@ RSpec.describe Gitlab::Conflict::File do ...@@ -298,12 +298,12 @@ RSpec.describe Gitlab::Conflict::File do
end end
it 'creates context sections of the correct length' do it 'creates context sections of the correct length' do
expect(sections[0][:lines].reject(&:type).length).to eq(3) expect(sections[0][:lines].count { |line| line.type.nil? }).to eq(3)
expect(sections[2][:lines].reject(&:type).length).to eq(3) expect(sections[2][:lines].count { |line| line.type.nil? }).to eq(3)
expect(sections[3][:lines].reject(&:type).length).to eq(3) expect(sections[3][:lines].count { |line| line.type.nil? }).to eq(3)
expect(sections[5][:lines].reject(&:type).length).to eq(3) expect(sections[5][:lines].count { |line| line.type.nil? }).to eq(3)
expect(sections[6][:lines].reject(&:type).length).to eq(3) expect(sections[6][:lines].count { |line| line.type.nil? }).to eq(3)
expect(sections[8][:lines].reject(&:type).length).to eq(1) expect(sections[8][:lines].count { |line| line.type.nil? }).to eq(1)
end end
end end
end end
......
...@@ -10,9 +10,9 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do ...@@ -10,9 +10,9 @@ RSpec.describe Gitlab::Git::Tree, :seed_helper do
it { expect(tree).to be_kind_of Array } it { expect(tree).to be_kind_of Array }
it { expect(tree.empty?).to be_falsey } it { expect(tree.empty?).to be_falsey }
it { expect(tree.select(&:dir?).size).to eq(2) } it { expect(tree.count(&:dir?)).to eq(2) }
it { expect(tree.select(&:file?).size).to eq(10) } it { expect(tree.count(&:file?)).to eq(10) }
it { expect(tree.select(&:submodule?).size).to eq(2) } it { expect(tree.count(&:submodule?)).to eq(2) }
it 'returns an empty array when called with an invalid ref' do it 'returns an empty array when called with an invalid ref' do
expect(described_class.where(repository, 'foobar-does-not-exist')).to eq([]) expect(described_class.where(repository, 'foobar-does-not-exist')).to eq([])
......
...@@ -1132,7 +1132,7 @@ RSpec.describe Ci::Build do ...@@ -1132,7 +1132,7 @@ RSpec.describe Ci::Build do
it "executes UPDATE query" do it "executes UPDATE query" do
recorded = ActiveRecord::QueryRecorder.new { subject } recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.log.select { |l| l.match?(/UPDATE.*ci_builds/) }.count).to eq(1) expect(recorded.log.count { |l| l.match?(/UPDATE.*ci_builds/) }).to eq(1)
end end
end end
...@@ -1140,7 +1140,7 @@ RSpec.describe Ci::Build do ...@@ -1140,7 +1140,7 @@ RSpec.describe Ci::Build do
it 'does not execute UPDATE query' do it 'does not execute UPDATE query' do
recorded = ActiveRecord::QueryRecorder.new { subject } recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.log.select { |l| l.match?(/UPDATE.*ci_builds/) }.count).to eq(0) expect(recorded.log.count { |l| l.match?(/UPDATE.*ci_builds/) }).to eq(0)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment