From 1670eed1401e254e6b05d77453b03d6fe8412c26 Mon Sep 17 00:00:00 2001 From: Rutger Wessels Date: Wed, 17 Sep 2025 09:58:54 +0200 Subject: [PATCH] Make cascaded setting lookup for projects more effiicent --- .../cascading_project_setting_attribute.rb | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/app/models/concerns/cascading_project_setting_attribute.rb b/app/models/concerns/cascading_project_setting_attribute.rb index 750e89ee3d4b98..8ab5eb81db9e18 100644 --- a/app/models/concerns/cascading_project_setting_attribute.rb +++ b/app/models/concerns/cascading_project_setting_attribute.rb @@ -137,16 +137,13 @@ def cascading_attribute_changed?(attribute) end def cascaded_ancestor_value(attribute) - return unless direct_ancestor_present? - - NamespaceSetting - .select(attribute) - .joins( - "join unnest(ARRAY[#{namespace_ancestor_ids_joined}]::bigint[]) with ordinality t(namespace_id, ord) - USING (namespace_id)" - ) - .where("#{attribute} IS NOT NULL") - .order('t.ord') + project + .group + .self_and_ancestors + .select(:id, namespace_settings: [attribute]) + .joins(:namespace_settings) + .where.not(namespace_settings: { attribute => nil }) + .order(Arel.sql("array_length(namespaces.traversal_ids, 1) desc")) .limit(1).first&.read_attribute(attribute) end @@ -158,10 +155,6 @@ def direct_ancestor_present? project.group.present? end - def namespace_ancestor_ids_joined - namespace_ancestor_ids.join(',') - end - def namespace_ancestor_ids project.project_namespace.ancestor_ids(hierarchy_order: :asc) end -- GitLab