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
Improve database performance when fetching custom field hierarchy
Cameron Dutro542cfd64b402
diff --git a/app/components/admin/custom_fields/hierarchy/tree_view_component.html.erb b/app/components/admin/custom_fields/hierarchy/tree_view_component.html.erbindex 13751bf8a3e..ed3a1fff18c 100644--- a/app/components/admin/custom_fields/hierarchy/tree_view_component.html.erb+++ b/app/components/admin/custom_fields/hierarchy/tree_view_component.html.erb@@ -30,8 +30,6 @@ See COPYRIGHT and LICENSE files for more details.<%=render(Primer::OpenProject::TreeView.new(node_variant: :anchor)) do |tree_view|- hierarchy_items.each do |item|- add_sub_tree(tree_view, item)- end+ add_sub_tree(tree_view, hierarchy_items)end%>diff --git a/app/components/admin/custom_fields/hierarchy/tree_view_component.rb b/app/components/admin/custom_fields/hierarchy/tree_view_component.rbindex 88d8c4b0c74..c29fac1f2f3 100644--- a/app/components/admin/custom_fields/hierarchy/tree_view_component.rb+++ b/app/components/admin/custom_fields/hierarchy/tree_view_component.rb@@ -41,16 +41,18 @@ module Adminenddef hierarchy_items- @custom_field.hierarchy_root.children+ @custom_field.hierarchy_root.hash_tree.first[1]end- def add_sub_tree(tree, item)- if item.children.empty?- tree.with_leaf(**item_options(item))- else- tree.with_sub_tree(expanded: expanded?(item), **item_options(item)) do |sub_tree|- item.children.each do |sub_item|- add_sub_tree(sub_tree, sub_item)+ def add_sub_tree(tree, hierarchy_hash)+ hierarchy_hash.each do |item, child_hash|+ if child_hash.empty?+ tree.with_leaf(**item_options(item))+ else+ expanded = child_hash.any? { |child, _| current?(child) }++ tree.with_sub_tree(expanded: expanded, **item_options(item)) do |sub_tree|+ add_sub_tree(sub_tree, child_hash)endendend@@ -67,10 +69,6 @@ module Admindef current?(item)item.id == @active_item.idend-- def expanded?(item)- @hierarchy_service.descendant_of?(item: @active_item, parent: item).success?- endendendend