Commit 7887790e authored by Marius Bobin's avatar Marius Bobin

Merge branch '348781-rename-contains_namespace' into 'master'

Rename contains_namespace to by_group_and_descendents

See merge request gitlab-org/gitlab!78883
parents 98150535 b37752d7
...@@ -6,7 +6,7 @@ module Ci ...@@ -6,7 +6,7 @@ module Ci
class NamespaceMirror < ApplicationRecord class NamespaceMirror < ApplicationRecord
belongs_to :namespace belongs_to :namespace
scope :contains_namespace, -> (id) do scope :by_group_and_descendants, -> (id) do
where('traversal_ids @> ARRAY[?]::int[]', id) where('traversal_ids @> ARRAY[?]::int[]', id)
end end
...@@ -32,7 +32,7 @@ module Ci ...@@ -32,7 +32,7 @@ module Ci
private private
def sync_children_namespaces!(namespace_id, traversal_ids) def sync_children_namespaces!(namespace_id, traversal_ids)
contains_namespace(namespace_id) by_group_and_descendants(namespace_id)
.where.not(namespace_id: namespace_id) .where.not(namespace_id: namespace_id)
.update_all( .update_all(
"traversal_ids = ARRAY[#{sanitize_sql(traversal_ids.join(','))}]::int[] || traversal_ids[array_position(traversal_ids, #{sanitize_sql(namespace_id)}) + 1:]" "traversal_ids = ARRAY[#{sanitize_sql(traversal_ids.join(','))}]::int[] || traversal_ids[array_position(traversal_ids, #{sanitize_sql(namespace_id)}) + 1:]"
......
...@@ -101,7 +101,7 @@ module Ci ...@@ -101,7 +101,7 @@ module Ci
} }
scope :belonging_to_group_or_project_descendants, -> (group_id) { scope :belonging_to_group_or_project_descendants, -> (group_id) {
group_ids = Ci::NamespaceMirror.contains_namespace(group_id).select(:namespace_id) group_ids = Ci::NamespaceMirror.by_group_and_descendants(group_id).select(:namespace_id)
project_ids = Ci::ProjectMirror.by_namespace_id(group_ids).select(:project_id) project_ids = Ci::ProjectMirror.by_namespace_id(group_ids).select(:project_id)
group_runners = joins(:runner_namespaces).where(ci_runner_namespaces: { namespace_id: group_ids }) group_runners = joins(:runner_namespaces).where(ci_runner_namespaces: { namespace_id: group_ids })
......
...@@ -20,10 +20,10 @@ RSpec.describe Ci::NamespaceMirror do ...@@ -20,10 +20,10 @@ RSpec.describe Ci::NamespaceMirror do
end end
context 'scopes' do context 'scopes' do
describe '.contains_namespace' do describe '.by_group_and_descendants' do
let_it_be(:another_group) { create(:group) } let_it_be(:another_group) { create(:group) }
subject(:result) { described_class.contains_namespace(group2.id) } subject(:result) { described_class.by_group_and_descendants(group2.id) }
it 'returns groups having group2.id in traversal_ids' do it 'returns groups having group2.id in traversal_ids' do
expect(result.pluck(:namespace_id)).to contain_exactly(group2.id, group3.id, group4.id) expect(result.pluck(:namespace_id)).to contain_exactly(group2.id, group3.id, group4.id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment