diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-08 18:08:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-08 18:08:41 +0300 |
commit | dc47d7f5c0f1a402463e9c1adaffecf3f465bc7f (patch) | |
tree | 5fbe362a06ef1841c73d6b377dbccc5dfc7fcece /lib/gitlab/object_hierarchy.rb | |
parent | a0158b1a9c21f648fdbf79765bbc1e19e776b5d9 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/object_hierarchy.rb')
-rw-r--r-- | lib/gitlab/object_hierarchy.rb | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/gitlab/object_hierarchy.rb b/lib/gitlab/object_hierarchy.rb index 41d80fe9aa6..c45018bf179 100644 --- a/lib/gitlab/object_hierarchy.rb +++ b/lib/gitlab/object_hierarchy.rb @@ -133,8 +133,8 @@ module Gitlab # Recursively get all the ancestors of the base set. parent_query = model - .from([objects_table, cte.table]) - .where(objects_table[:id].eq(cte.table[:parent_id])) + .from(from_tables(cte)) + .where(ancestor_conditions(cte)) .except(:order) if hierarchy_order @@ -148,7 +148,7 @@ module Gitlab ).where(cte.table[:tree_cycle].eq(false)) end - parent_query = parent_query.where(cte.table[:parent_id].not_eq(stop_id)) if stop_id + parent_query = parent_query.where(parent_id_column(cte).not_eq(stop_id)) if stop_id cte << parent_query cte @@ -166,8 +166,8 @@ module Gitlab # Recursively get all the descendants of the base set. descendants_query = model - .from([objects_table, cte.table]) - .where(objects_table[:parent_id].eq(cte.table[:id])) + .from(from_tables(cte)) + .where(descendant_conditions(cte)) .except(:order) if with_depth @@ -190,6 +190,22 @@ module Gitlab model.arel_table end + def parent_id_column(cte) + cte.table[:parent_id] + end + + def from_tables(cte) + [objects_table, cte.table] + end + + def ancestor_conditions(cte) + objects_table[:id].eq(cte.table[:parent_id]) + end + + def descendant_conditions(cte) + objects_table[:parent_id].eq(cte.table[:id]) + end + def read_only(relation) # relations using a CTE are not safe to use with update_all as it will # throw away the CTE, hence we mark them as read-only. |