Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fixes Performance/Sum offenses

Klaus Zandersb853acafb0fc
diff --git a/lib/api/v3/notifications/property_factory.rb b/lib/api/v3/notifications/property_factory.rb
index ff2bd09cee8..73b212950f0 100644
--- a/lib/api/v3/notifications/property_factory.rb
+++ b/lib/api/v3/notifications/property_factory.rb
@@ -64,7 +64,7 @@ module API::V3::Notifications
# Returns the outward facing notification group attributes
def groups_for(values)
group_values = values.except(*DATE_ALERT_REASONS)
- date_alert_values = values.slice(*DATE_ALERT_REASONS).values.reduce(:+)
+ date_alert_values = values.slice(*DATE_ALERT_REASONS).values.sum
group_values["dateAlert"] = date_alert_values if date_alert_values
group_values
end
diff --git a/modules/costs/lib/costs/attributes_helper.rb b/modules/costs/lib/costs/attributes_helper.rb
index f31546abdce..39b0a8fe476 100644
--- a/modules/costs/lib/costs/attributes_helper.rb
+++ b/modules/costs/lib/costs/attributes_helper.rb
@@ -76,12 +76,12 @@ module Costs
def material_costs
cost_entries_with_rate = cost_entries.select { |c| c.costs_visible_by?(@user) }
- cost_entries_with_rate.blank? ? nil : cost_entries_with_rate.map(&:real_costs).sum
+ cost_entries_with_rate.blank? ? nil : cost_entries_with_rate.sum(&:real_costs)
end
def labor_costs
time_entries_with_rate = time_entries.select { |c| c.costs_visible_by?(@user) }
- time_entries_with_rate.blank? ? nil : time_entries_with_rate.map(&:real_costs).sum
+ time_entries_with_rate.blank? ? nil : time_entries_with_rate.sum(&:real_costs)
end
def user_allowed_to?(*privileges)
diff --git a/modules/reporting/spec/models/cost_query/result_spec.rb b/modules/reporting/spec/models/cost_query/result_spec.rb
index 537eeaa7fdf..11d6e97ce72 100644
--- a/modules/reporting/spec/models/cost_query/result_spec.rb
+++ b/modules/reporting/spec/models/cost_query/result_spec.rb
@@ -109,11 +109,11 @@ RSpec.describe CostQuery, reporting_query_helper: true do
end
it "computes units correctly" do
- expect(query.result.units).to eq(Entry.all.map(&:units).sum)
+ expect(query.result.units).to eq(Entry.all.sum(&:units))
end
it "computes real_costs correctly" do
- expect(query.result.real_costs).to eq(Entry.all.map { |e| e.overridden_costs || e.costs }.sum)
+ expect(query.result.real_costs).to eq(Entry.all.sum { |e| e.overridden_costs || e.costs })
end
it "computes count for DirectResults" do