]> source.dussan.org Git - redmine.git/commitdiff
Use sum { ... } instead of map { ... }.sum (#34399).
authorGo MAEDA <maeda@farend.jp>
Sun, 6 Dec 2020 01:36:39 +0000 (01:36 +0000)
committerGo MAEDA <maeda@farend.jp>
Sun, 6 Dec 2020 01:36:39 +0000 (01:36 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@20581 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
app/models/project.rb

index bda93ddc8cabbdfc513ed321a66131d72bbaf856..6132f71e65773ddfc3e32d51403fa7fced702d86 100644 (file)
@@ -1743,16 +1743,16 @@ class Issue < ActiveRecord::Base
           if children.any?
             child_with_total_estimated_hours = children.select {|c| c.total_estimated_hours.to_f > 0.0}
             if child_with_total_estimated_hours.any?
-              average = child_with_total_estimated_hours.map(&:total_estimated_hours).sum.to_d / child_with_total_estimated_hours.count
+              average = child_with_total_estimated_hours.sum(&:total_estimated_hours).to_d / child_with_total_estimated_hours.count
             else
               average = 1.0.to_d
             end
-            done = children.map do |c|
+            done = children.sum do |c|
               estimated = (c.total_estimated_hours || 0.0).to_d
               estimated = average unless estimated > 0.0
               ratio = c.closed? ? 100 : (c.done_ratio || 0)
               estimated * ratio
-            end.sum
+            end
             progress = done / (average * children.count)
             p.done_ratio = progress.floor
           end
index 9ffcd1421b558ef5491b0854fe8bd46e862aa178..44adeea58474b8bb77877a76cc74357d4b9928eb 100644 (file)
@@ -677,12 +677,12 @@ class Project < ActiveRecord::Base
   # progress on it's versions.
   def completed_percent(options={:include_subprojects => false})
     if options.delete(:include_subprojects)
-      total = self_and_descendants.collect(&:completed_percent).sum
+      total = self_and_descendants.sum(&:completed_percent)
 
       total / self_and_descendants.count
     else
       if versions.count > 0
-        total = versions.collect(&:completed_percent).sum
+        total = versions.sum(&:completed_percent)
 
         total / versions.count
       else