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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Remove N+1 queries from the ProjectCustomFields rendering inside the custom field sections
Dombi Attilac68d1a5c3464
diff --git a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb b/app/components/settings/project_custom_field_sections/custom_field_row_component.rbindex 4a5ad54384d..1b203dabce3 100644--- a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb+++ b/app/components/settings/project_custom_field_sections/custom_field_row_component.rb@@ -33,10 +33,11 @@ module Settingsinclude OpPrimer::ComponentHelpersinclude OpTurbo::Streamable- def initialize(project_custom_field:)+ def initialize(project_custom_field:, first_and_last:)super@project_custom_field = project_custom_field+ @first_and_last = first_and_lastendprivate@@ -50,17 +51,12 @@ module Settingsenddef move_actions(menu)- # TODO: these methods trigger database queries for each custom field displayed- # it would be nice if can eager load this information- first_in_list = @project_custom_field.first?- last_in_list = @project_custom_field.last?-- unless first_in_list+ unless first?move_action_item(menu, :highest, t("label_agenda_item_move_to_top"),"move-to-top")move_action_item(menu, :higher, t("label_agenda_item_move_up"), "chevron-up")end- unless last_in_list+ unless last?move_action_item(menu, :lower, t("label_agenda_item_move_down"),"chevron-down")move_action_item(menu, :lowest, t("label_agenda_item_move_to_bottom"),@@ -99,6 +95,24 @@ module Settings"#{project_count} #{t('label_project_plural')}"endend++ def first?+ @first ||=+ if @first_and_last.first+ @first_and_last.first == @project_custom_field+ else+ @project_custom_field.first?+ end+ end++ def last?+ @last ||=+ if @first_and_last.last+ @first_and_last.last == @project_custom_field+ else+ @project_custom_field.last?+ end+ endendendenddiff --git a/app/components/settings/project_custom_field_sections/show_component.html.erb b/app/components/settings/project_custom_field_sections/show_component.html.erbindex a7878c81493..ea991c88738 100644--- a/app/components/settings/project_custom_field_sections/show_component.html.erb+++ b/app/components/settings/project_custom_field_sections/show_component.html.erb@@ -59,11 +59,17 @@endendelse+ first_and_last = [@project_custom_fields.first, @project_custom_fields.last]@project_custom_fields.each do |project_custom_field|component.with_row(data: draggable_item_config(project_custom_field)) do- render(Settings::ProjectCustomFieldSections::CustomFieldRowComponent.new(project_custom_field:))+ render(+ ::Settings::ProjectCustomFieldSections::CustomFieldRowComponent.new(+ project_custom_field:,+ first_and_last:+ )+ )endendenddiff --git a/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb b/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rbindex 8bb0724cf73..1e1f1cd5f2d 100644--- a/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb+++ b/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb@@ -48,20 +48,6 @@ module Projects))end-- def update_custom_field_row_via_turbo_stream(- project: @project,- project_custom_field: @project_custom_field,- project_custom_field_project_mappings: @project_custom_field_project_mappings- )- update_via_turbo_stream(- component: ::Projects::Settings::ProjectCustomFieldSections::CustomFieldRowComponent.new(- project:,- project_custom_field:,- project_custom_field_project_mappings:- )- )- endendendend