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

Use available_custom_values to avoid loading CFs individually

Oliver Günther718bc2978821
diff --git a/app/models/exports/formatters/custom_field.rb b/app/models/exports/formatters/custom_field.rb
index 153892c7f30..ef6e3ba604b 100644
--- a/app/models/exports/formatters/custom_field.rb
+++ b/app/models/exports/formatters/custom_field.rb
@@ -8,6 +8,7 @@ module Exports
##
# Takes a WorkPackage and an attribute and returns the value to be exported.
def retrieve_value(object)
+ custom_field = find_custom_field(object)
return '' if custom_field.nil?
object.formatted_custom_value_for(custom_field)
@@ -15,12 +16,9 @@ module Exports
##
# Finds a custom field from the attribute identifier
- def custom_field
- unless defined?(@custom_field)
- @custom_field = ::CustomField.find_by(id: attribute.to_s.sub('cf_', '').to_i)
- end
-
- @custom_field
+ def find_custom_field(object)
+ id = attribute.to_s.sub('cf_', '').to_i
+ object.available_custom_fields.detect { |cf| cf.id == id }
end
end
end
diff --git a/app/models/projects/exports/query_exporter.rb b/app/models/projects/exports/query_exporter.rb
index 5d08073583f..6f72299aa2c 100644
--- a/app/models/projects/exports/query_exporter.rb
+++ b/app/models/projects/exports/query_exporter.rb
@@ -46,6 +46,7 @@ module Projects::Exports
.results
.with_required_storage
.with_latest_activity
+ .includes(:custom_values)
.page(page)
.per_page(Setting.work_packages_export_limit.to_i)
end