Commit c223a602 authored by Siddharth Asthana's avatar Siddharth Asthana

Resolve Performance/Sum rubocop offenses

Changelog: other
EE: true
parent 92914b5a
......@@ -311,23 +311,6 @@ Performance/StringInclude:
- 'spec/spec_helper.rb'
- 'spec/support_specs/helpers/active_record/query_recorder_spec.rb'
# Offense count: 18
# Cop supports --auto-correct.
Performance/Sum:
Exclude:
- 'app/controllers/projects/pipelines/tests_controller.rb'
- 'app/models/application_setting_implementation.rb'
- 'app/models/ci/pipeline.rb'
- 'app/services/issues/export_csv_service.rb'
- 'ee/spec/lib/gitlab/elastic/bulk_indexer_spec.rb'
- 'lib/api/entities/issuable_time_stats.rb'
- 'lib/container_registry/tag.rb'
- 'lib/gitlab/ci/reports/test_suite_comparer.rb'
- 'lib/gitlab/diff/file.rb'
- 'lib/gitlab/usage_data.rb'
- 'lib/peek/views/detailed_view.rb'
- 'spec/models/namespace/root_storage_statistics_spec.rb'
# Offense count: 15209
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
......
......@@ -42,9 +42,9 @@ module Projects
end
def test_suite
suite = builds.map do |build|
suite = builds.sum do |build|
build.collect_test_reports!(Gitlab::Ci::Reports::TestReports.new)
end.sum
end
Gitlab::Ci::Reports::TestFailureHistory.new(suite.failed.values, project).load!
......
......@@ -403,7 +403,7 @@ module ApplicationSettingImplementation
def normalized_repository_storage_weights
strong_memoize(:normalized_repository_storage_weights) do
repository_storages_weights = repository_storages_weighted.slice(*Gitlab.config.repositories.storages.keys)
weights_total = repository_storages_weights.values.reduce(:+)
weights_total = repository_storages_weights.values.sum
repository_storages_weights.transform_values do |w|
next w if weights_total == 0
......
......@@ -653,7 +653,7 @@ module Ci
def coverage
coverage_array = latest_statuses.map(&:coverage).compact
if coverage_array.size >= 1
coverage_array.reduce(:+) / coverage_array.size
coverage_array.sum / coverage_array.size
end
end
......
......@@ -52,7 +52,7 @@ module Issues
# rubocop: disable CodeReuse/ActiveRecord
def issue_time_spent(issue)
issue.timelogs.map(&:time_spent).sum
issue.timelogs.sum(&:time_spent)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......
......@@ -53,7 +53,7 @@ RSpec.describe Gitlab::Elastic::BulkIndexer, :elastic, :clean_gitlab_redis_share
indexer.process(issue_as_ref)
expect(es_client).to have_received(:bulk) do |args|
body_bytesize = args[:body].map(&:bytesize).reduce(:+)
body_bytesize = args[:body].sum(&:bytesize)
expect(body_bytesize).to be <= bulk_limit_bytes
end
......@@ -109,7 +109,7 @@ RSpec.describe Gitlab::Elastic::BulkIndexer, :elastic, :clean_gitlab_redis_share
indexer.process(issue_as_ref)
expect(es_client).to have_received(:bulk) do |args|
body_bytesize = args[:body].map(&:bytesize).reduce(:+)
body_bytesize = args[:body].sum(&:bytesize)
expect(body_bytesize).to be <= bulk_limit_bytes
end
......
......@@ -18,7 +18,7 @@ module API
# rubocop: disable CodeReuse/ActiveRecord
def total_time_spent
# Avoids an N+1 query since timelogs are preloaded
object.timelogs.map(&:time_spent).sum
object.timelogs.sum(&:time_spent)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......
......@@ -104,7 +104,7 @@ module ContainerRegistry
def total_size
return unless layers
layers.map(&:size).sum if v2?
layers.sum(&:size) if v2?
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -106,7 +106,7 @@ module Gitlab
private
def max_tests(*used)
[DEFAULT_MAX_TESTS - used.map(&:count).sum, DEFAULT_MIN_TESTS].max
[DEFAULT_MAX_TESTS - used.sum(&:count), DEFAULT_MIN_TESTS].max
end
end
end
......
......@@ -296,13 +296,13 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def size
valid_blobs.map(&:size).sum
valid_blobs.sum(&:size)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def raw_size
valid_blobs.map(&:raw_size).sum
valid_blobs.sum(&:raw_size)
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -23,7 +23,7 @@ module Peek
private
def duration
detail_store.map { |entry| entry[:duration] }.sum * 1000
detail_store.sum { |entry| entry[:duration] } * 1000
end
def calls
......
......@@ -178,7 +178,7 @@ RSpec.describe Namespace::RootStorageStatistics, type: :model do
snippets = create_list(:personal_snippet, 3, :repository, author: user)
snippets.each { |s| s.statistics.refresh! }
total_personal_snippets_size = snippets.map { |s| s.statistics.repository_size }.sum
total_personal_snippets_size = snippets.sum { |s| s.statistics.repository_size }
root_storage_statistics.recalculate!
......
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