Commit e75847ce authored by Bob Van Landuyt's avatar Bob Van Landuyt

Move pages async when transferring projects

When moving a project across namespaces, the pages need to be moved on
disk if there are any.

This performs that move in the background if there are pages, but
skips the move if there aren't any, to avoid unnecessary jobs.

It also performs the move or the scheduling of the database
transaction.
parent 1a4cdc25
...@@ -88,15 +88,14 @@ module Projects ...@@ -88,15 +88,14 @@ module Projects
# Move uploads # Move uploads
move_project_uploads(project) move_project_uploads(project)
# Move pages
Gitlab::PagesTransfer.new.move_project(project.path, @old_namespace.full_path, @new_namespace.full_path)
project.old_path_with_namespace = @old_path project.old_path_with_namespace = @old_path
update_repository_configuration(@new_path) update_repository_configuration(@new_path)
execute_system_hooks execute_system_hooks
end end
move_pages(project)
rescue Exception # rubocop:disable Lint/RescueException rescue Exception # rubocop:disable Lint/RescueException
rollback_side_effects rollback_side_effects
raise raise
...@@ -181,6 +180,19 @@ module Projects ...@@ -181,6 +180,19 @@ module Projects
) )
end end
def move_pages(project)
transfer = Gitlab::PagesTransfer.new
if Feature.enabled?(:async_pages_move_project_transfer, project)
# Avoid scheduling moves for directories that don't exist.
return unless project.pages_deployed?
transfer = transfer.async
end
transfer.move_project(project.path, @old_namespace.full_path, @new_namespace.full_path)
end
def old_wiki_repo_path def old_wiki_repo_path
"#{old_path}#{::Gitlab::GlRepository::WIKI.path_suffix}" "#{old_path}#{::Gitlab::GlRepository::WIKI.path_suffix}"
end end
......
---
name: async_pages_move_project_transfer
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40492
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/235757
group: team::Scalability
type: development
default_enabled: false
...@@ -5,8 +5,8 @@ require 'spec_helper' ...@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec.describe Projects::TransferService do RSpec.describe Projects::TransferService do
include GitHelpers include GitHelpers
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:group) { create(:group) } let_it_be(:group) { create(:group) }
let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) } let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) }
subject(:execute_transfer) { described_class.new(project, user).execute(group) } subject(:execute_transfer) { described_class.new(project, user).execute(group) }
...@@ -489,6 +489,43 @@ RSpec.describe Projects::TransferService do ...@@ -489,6 +489,43 @@ RSpec.describe Projects::TransferService do
end end
end end
context 'moving pages' do
let_it_be(:project) { create(:project, namespace: user.namespace) }
before do
group.add_owner(user)
end
it 'schedules a job when pages are deployed' do
project.mark_pages_as_deployed
expect(PagesTransferWorker).to receive(:perform_async)
.with("move_project", [project.path, user.namespace.full_path, group.full_path])
execute_transfer
end
it 'does not schedule a job when no pages are deployed' do
expect(PagesTransferWorker).not_to receive(:perform_async)
execute_transfer
end
context 'when async_pages_move_project_transfer is disabled' do
before do
stub_feature_flags(async_pages_move_project_transfer: false)
end
it 'moves pages inline' do
expect_next_instance_of(Gitlab::PagesTransfer) do |transfer|
expect(transfer).to receive(:move_project).with(project.path, user.namespace.full_path, group.full_path)
end
execute_transfer
end
end
end
def rugged_config def rugged_config
rugged_repo(project.repository).config rugged_repo(project.repository).config
end end
......
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