Commit 63732b69 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch '339457-fj-use-linear-roots-mirrors-worker' into 'master'

Introduce linear root method in UpdateAllMirrorsWorker

See merge request gitlab-org/gitlab!76735
parents 1f199e00 9300a7e5
---
name: linear_mirrors_worker_roots
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/76735
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/348415
milestone: '14.7'
type: development
group: group::authentication and authorization
default_enabled: false
...@@ -117,12 +117,6 @@ class UpdateAllMirrorsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -117,12 +117,6 @@ class UpdateAllMirrorsWorker # rubocop:disable Scalability/IdempotentWorker
relation = relation.where('import_state.next_execution_timestamp > ?', offset_at) if offset_at relation = relation.where('import_state.next_execution_timestamp > ?', offset_at) if offset_at
if check_mirror_plans_in_query? if check_mirror_plans_in_query?
root_namespaces_sql = Gitlab::ObjectHierarchy
.new(Namespace.where('id = projects.namespace_id'))
.roots
.select(:id)
.to_sql
root_namespaces_join = "INNER JOIN namespaces AS root_namespaces ON root_namespaces.id = (#{root_namespaces_sql})" root_namespaces_join = "INNER JOIN namespaces AS root_namespaces ON root_namespaces.id = (#{root_namespaces_sql})"
relation = relation relation = relation
...@@ -147,4 +141,19 @@ class UpdateAllMirrorsWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -147,4 +141,19 @@ class UpdateAllMirrorsWorker # rubocop:disable Scalability/IdempotentWorker
def check_mirror_plans_in_query? def check_mirror_plans_in_query?
::Gitlab::CurrentSettings.should_check_namespace_plan? ::Gitlab::CurrentSettings.should_check_namespace_plan?
end end
# rubocop: disable CodeReuse/ActiveRecord
def root_namespaces_sql
namespace = Namespace.where('id = projects.namespace_id')
if Feature.enabled?(:linear_mirrors_worker_roots, default_enabled: :yaml)
namespace.roots.as_ids
else
Gitlab::ObjectHierarchy
.new(namespace)
.roots
.select(:id)
end.to_sql
end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -187,6 +187,7 @@ RSpec.describe UpdateAllMirrorsWorker do ...@@ -187,6 +187,7 @@ RSpec.describe UpdateAllMirrorsWorker do
let(:unlicensed_projects) { [unlicensed_project1, unlicensed_project2, unlicensed_project3, unlicensed_project4] } let(:unlicensed_projects) { [unlicensed_project1, unlicensed_project2, unlicensed_project3, unlicensed_project4] }
context 'when using SQL to filter projects' do context 'when using SQL to filter projects' do
shared_examples 'examples checking namespace plans' do
before do before do
allow(subject).to receive(:check_mirror_plans_in_query?).and_return(true) allow(subject).to receive(:check_mirror_plans_in_query?).and_return(true)
end end
...@@ -212,6 +213,17 @@ RSpec.describe UpdateAllMirrorsWorker do ...@@ -212,6 +213,17 @@ RSpec.describe UpdateAllMirrorsWorker do
end end
end end
it_behaves_like 'examples checking namespace plans'
context 'when feature flag ' do
before do
stub_feature_flags(linear_mirrors_worker_roots: false)
end
it_behaves_like 'examples checking namespace plans'
end
end
context 'when checking licenses on each record individually' do context 'when checking licenses on each record individually' do
before do before do
allow(subject).to receive(:check_mirror_plans_in_query?).and_return(false) allow(subject).to receive(:check_mirror_plans_in_query?).and_return(false)
......
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