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

Avoid N+1 queries on the ProjectCustomFieldSections

Dombi Attilab1444429be89
diff --git a/app/components/settings/project_custom_field_sections/show_component.rb b/app/components/settings/project_custom_field_sections/show_component.rb
index e9fc4eab56b..1f3ed82c392 100644
--- a/app/components/settings/project_custom_field_sections/show_component.rb
+++ b/app/components/settings/project_custom_field_sections/show_component.rb
@@ -37,7 +37,7 @@ module Settings
super
@project_custom_field_section = project_custom_field_section
- @project_custom_fields = project_custom_field_section.custom_fields.reorder(position_in_custom_field_section: :asc)
+ @project_custom_fields = project_custom_field_section.custom_fields
end
private
diff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rb
index 9dcc5169df0..f25cca6013d 100644
--- a/app/controllers/admin/settings/project_custom_fields_controller.rb
+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb
@@ -111,6 +111,7 @@ module Admin::Settings
def set_sections
@project_custom_field_sections = ProjectCustomFieldSection
.includes(custom_fields: :project_custom_field_project_mappings)
+ .order("custom_fields.position_in_custom_field_section ASC")
.all
end
diff --git a/app/models/custom_field_section.rb b/app/models/custom_field_section.rb
index 7d1cd811a4a..8ca5ae147a0 100644
--- a/app/models/custom_field_section.rb
+++ b/app/models/custom_field_section.rb
@@ -27,8 +27,6 @@
#++
class CustomFieldSection < ApplicationRecord
- has_many :custom_fields, dependent: :destroy
-
acts_as_list scope: [:type]
validates :name, presence: true
diff --git a/app/models/project_custom_field_section.rb b/app/models/project_custom_field_section.rb
index fcfe4b98ae5..22a9ef3114e 100644
--- a/app/models/project_custom_field_section.rb
+++ b/app/models/project_custom_field_section.rb
@@ -27,4 +27,5 @@
#++
class ProjectCustomFieldSection < CustomFieldSection
+ has_many :custom_fields, class_name: "ProjectCustomField", dependent: :destroy
end