Commit 9fb8a54d authored by Sean McGivern's avatar Sean McGivern

Only schedule PagesTransferWorker when namespace has pages

When we change a namespace's path, we only need to move pages
directories on disk for its projects if it has any projects with
deployed pages sites.
parent 75cfe861
...@@ -25,9 +25,11 @@ module Storage ...@@ -25,9 +25,11 @@ module Storage
Gitlab::UploadsTransfer.new.move_namespace(path, former_parent_full_path, parent_full_path) Gitlab::UploadsTransfer.new.move_namespace(path, former_parent_full_path, parent_full_path)
if ::Feature.enabled?(:async_pages_move_namespace_transfer, self) if ::Feature.enabled?(:async_pages_move_namespace_transfer, self)
if any_project_with_pages_deployed?
run_after_commit do run_after_commit do
Gitlab::PagesTransfer.new.async.move_namespace(path, former_parent_full_path, parent_full_path) Gitlab::PagesTransfer.new.async.move_namespace(path, former_parent_full_path, parent_full_path)
end end
end
else else
Gitlab::PagesTransfer.new.move_namespace(path, former_parent_full_path, parent_full_path) Gitlab::PagesTransfer.new.move_namespace(path, former_parent_full_path, parent_full_path)
end end
...@@ -35,11 +37,13 @@ module Storage ...@@ -35,11 +37,13 @@ module Storage
Gitlab::UploadsTransfer.new.rename_namespace(full_path_before_last_save, full_path) Gitlab::UploadsTransfer.new.rename_namespace(full_path_before_last_save, full_path)
if ::Feature.enabled?(:async_pages_move_namespace_rename, self) if ::Feature.enabled?(:async_pages_move_namespace_rename, self)
if any_project_with_pages_deployed?
full_path_was = full_path_before_last_save full_path_was = full_path_before_last_save
run_after_commit do run_after_commit do
Gitlab::PagesTransfer.new.async.rename_namespace(full_path_was, full_path) Gitlab::PagesTransfer.new.async.rename_namespace(full_path_was, full_path)
end end
end
else else
Gitlab::PagesTransfer.new.rename_namespace(full_path_before_last_save, full_path) Gitlab::PagesTransfer.new.rename_namespace(full_path_before_last_save, full_path)
end end
......
...@@ -353,6 +353,10 @@ class Namespace < ApplicationRecord ...@@ -353,6 +353,10 @@ class Namespace < ApplicationRecord
) )
end end
def any_project_with_pages_deployed?
all_projects.with_pages_deployed.any?
end
def closest_setting(name) def closest_setting(name)
self_and_ancestors(hierarchy_order: :asc) self_and_ancestors(hierarchy_order: :asc)
.find { |n| !n.read_attribute(name).nil? } .find { |n| !n.read_attribute(name).nil? }
......
...@@ -391,14 +391,14 @@ RSpec.describe Namespace do ...@@ -391,14 +391,14 @@ RSpec.describe Namespace do
let(:uploads_dir) { FileUploader.root } let(:uploads_dir) { FileUploader.root }
let(:pages_dir) { File.join(TestEnv.pages_path) } let(:pages_dir) { File.join(TestEnv.pages_path) }
def expect_project_directories_at(namespace_path) def expect_project_directories_at(namespace_path, with_pages: true)
expected_repository_path = File.join(TestEnv.repos_path, namespace_path, 'the-project.git') expected_repository_path = File.join(TestEnv.repos_path, namespace_path, 'the-project.git')
expected_upload_path = File.join(uploads_dir, namespace_path, 'the-project') expected_upload_path = File.join(uploads_dir, namespace_path, 'the-project')
expected_pages_path = File.join(pages_dir, namespace_path, 'the-project') expected_pages_path = File.join(pages_dir, namespace_path, 'the-project')
expect(File.directory?(expected_repository_path)).to be_truthy expect(File.directory?(expected_repository_path)).to be_truthy
expect(File.directory?(expected_upload_path)).to be_truthy expect(File.directory?(expected_upload_path)).to be_truthy
expect(File.directory?(expected_pages_path)).to be_truthy expect(File.directory?(expected_pages_path)).to be(with_pages)
end end
before do before do
...@@ -412,7 +412,7 @@ RSpec.describe Namespace do ...@@ -412,7 +412,7 @@ RSpec.describe Namespace do
FileUtils.remove_entry(File.join(TestEnv.repos_path, new_parent.full_path), true) FileUtils.remove_entry(File.join(TestEnv.repos_path, new_parent.full_path), true)
FileUtils.remove_entry(File.join(TestEnv.repos_path, child.full_path), true) FileUtils.remove_entry(File.join(TestEnv.repos_path, child.full_path), true)
FileUtils.remove_entry(File.join(uploads_dir, project.full_path), true) FileUtils.remove_entry(File.join(uploads_dir, project.full_path), true)
FileUtils.remove_entry(File.join(pages_dir, project.full_path), true) FileUtils.remove_entry(pages_dir, true)
end end
context 'renaming child' do context 'renaming child' do
...@@ -426,12 +426,24 @@ RSpec.describe Namespace do ...@@ -426,12 +426,24 @@ RSpec.describe Namespace do
end end
end end
context 'when no projects have pages deployed' do
it 'moves the repository and uploads', :sidekiq_inline do
project.pages_metadatum.update!(deployed: false)
child.update!(path: 'renamed')
expect_project_directories_at('parent/renamed', with_pages: false)
end
end
context 'when the project has pages deployed' do
it 'correctly moves the repository, uploads and pages', :sidekiq_inline do it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
project.pages_metadatum.update!(deployed: true)
child.update!(path: 'renamed') child.update!(path: 'renamed')
expect_project_directories_at('parent/renamed') expect_project_directories_at('parent/renamed')
end end
end end
end
context 'renaming parent' do context 'renaming parent' do
context 'when async_pages_move_namespace_rename is disabled' do context 'when async_pages_move_namespace_rename is disabled' do
...@@ -444,12 +456,24 @@ RSpec.describe Namespace do ...@@ -444,12 +456,24 @@ RSpec.describe Namespace do
end end
end end
context 'when no projects have pages deployed' do
it 'moves the repository and uploads', :sidekiq_inline do
project.pages_metadatum.update!(deployed: false)
parent.update!(path: 'renamed')
expect_project_directories_at('renamed/child', with_pages: false)
end
end
context 'when the project has pages deployed' do
it 'correctly moves the repository, uploads and pages', :sidekiq_inline do it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
project.pages_metadatum.update!(deployed: true)
parent.update!(path: 'renamed') parent.update!(path: 'renamed')
expect_project_directories_at('renamed/child') expect_project_directories_at('renamed/child')
end end
end end
end
context 'moving from one parent to another' do context 'moving from one parent to another' do
context 'when async_pages_move_namespace_transfer is disabled' do context 'when async_pages_move_namespace_transfer is disabled' do
...@@ -462,12 +486,24 @@ RSpec.describe Namespace do ...@@ -462,12 +486,24 @@ RSpec.describe Namespace do
end end
end end
context 'when no projects have pages deployed' do
it 'moves the repository and uploads', :sidekiq_inline do
project.pages_metadatum.update!(deployed: false)
child.update!(parent: new_parent)
expect_project_directories_at('new_parent/child', with_pages: false)
end
end
context 'when the project has pages deployed' do
it 'correctly moves the repository, uploads and pages', :sidekiq_inline do it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
project.pages_metadatum.update!(deployed: true)
child.update!(parent: new_parent) child.update!(parent: new_parent)
expect_project_directories_at('new_parent/child') expect_project_directories_at('new_parent/child')
end end
end end
end
context 'moving from having a parent to root' do context 'moving from having a parent to root' do
context 'when async_pages_move_namespace_transfer is disabled' do context 'when async_pages_move_namespace_transfer is disabled' do
...@@ -480,12 +516,24 @@ RSpec.describe Namespace do ...@@ -480,12 +516,24 @@ RSpec.describe Namespace do
end end
end end
context 'when no projects have pages deployed' do
it 'moves the repository and uploads', :sidekiq_inline do
project.pages_metadatum.update!(deployed: false)
child.update!(parent: nil)
expect_project_directories_at('child', with_pages: false)
end
end
context 'when the project has pages deployed' do
it 'correctly moves the repository, uploads and pages', :sidekiq_inline do it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
project.pages_metadatum.update!(deployed: true)
child.update!(parent: nil) child.update!(parent: nil)
expect_project_directories_at('child') expect_project_directories_at('child')
end end
end end
end
context 'moving from root to having a parent' do context 'moving from root to having a parent' do
context 'when async_pages_move_namespace_transfer is disabled' do context 'when async_pages_move_namespace_transfer is disabled' do
...@@ -498,7 +546,18 @@ RSpec.describe Namespace do ...@@ -498,7 +546,18 @@ RSpec.describe Namespace do
end end
end end
context 'when no projects have pages deployed' do
it 'moves the repository and uploads', :sidekiq_inline do
project.pages_metadatum.update!(deployed: false)
parent.update!(parent: new_parent)
expect_project_directories_at('new_parent/parent/child', with_pages: false)
end
end
context 'when the project has pages deployed' do
it 'correctly moves the repository, uploads and pages', :sidekiq_inline do it 'correctly moves the repository, uploads and pages', :sidekiq_inline do
project.pages_metadatum.update!(deployed: true)
parent.update!(parent: new_parent) parent.update!(parent: new_parent)
expect_project_directories_at('new_parent/parent/child') expect_project_directories_at('new_parent/parent/child')
...@@ -506,6 +565,7 @@ RSpec.describe Namespace do ...@@ -506,6 +565,7 @@ RSpec.describe Namespace do
end end
end end
end end
end
context 'hashed storage' do context 'hashed storage' do
let(:namespace) { create(:namespace) } let(:namespace) { create(:namespace) }
...@@ -1174,6 +1234,27 @@ RSpec.describe Namespace do ...@@ -1174,6 +1234,27 @@ RSpec.describe Namespace do
end end
end end
describe '#any_project_with_pages_deployed?' do
it 'returns true if any project nested under the group has pages deployed' do
parent_1 = create(:group) # Three projects, one with pages
child_1_1 = create(:group, parent: parent_1) # Two projects, one with pages
child_1_2 = create(:group, parent: parent_1) # One project, no pages
parent_2 = create(:group) # No projects
create(:project, group: child_1_1).tap do |project|
project.pages_metadatum.update!(deployed: true)
end
create(:project, group: child_1_1)
create(:project, group: child_1_2)
expect(parent_1.any_project_with_pages_deployed?).to be(true)
expect(child_1_1.any_project_with_pages_deployed?).to be(true)
expect(child_1_2.any_project_with_pages_deployed?).to be(false)
expect(parent_2.any_project_with_pages_deployed?).to be(false)
end
end
describe '#has_parent?' do describe '#has_parent?' do
it 'returns true when the group has a parent' do it 'returns true when the group has a parent' do
group = create(:group, :nested) group = create(:group, :nested)
......
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