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

refactor: fetch all children dates at once

Christophe Bliardb9bc90e9c704
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rb
index 34ce7b993b0..41cb8bad17a 100644
--- a/app/services/work_packages/set_attributes_service.rb
+++ b/app/services/work_packages/set_attributes_service.rb
@@ -347,7 +347,7 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributes
end
def min_child_date
- (work_package.children.map(&:start_date) + work_package.children.map(&:due_date)).compact.min
+ children_dates.min
end
def children_duration
@@ -362,7 +362,11 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributes
end
def max_child_date
- (work_package.children.map(&:start_date) + work_package.children.map(&:due_date)).compact.max
+ children_dates.max
+ end
+
+ def children_dates
+ @children_dates ||= work_package.children.pluck(:start_date, :due_date).flatten.compact
end
def parent_start_earlier_than_due?