Commit 37a79409 authored by Toon Claes's avatar Toon Claes

No user needed to cleanup namespaceless pending delete projects

Since this is a cleanup, ran by a post-deploy, there is no need to lookup the
admin to run the cleanup.
parent 0ad80cab
...@@ -12,7 +12,7 @@ class NamespacelessProjectDestroyWorker ...@@ -12,7 +12,7 @@ class NamespacelessProjectDestroyWorker
Sidekiq::Client.push_bulk('class' => self, 'queue' => sidekiq_options['queue'], 'args' => args_list) Sidekiq::Client.push_bulk('class' => self, 'queue' => sidekiq_options['queue'], 'args' => args_list)
end end
def perform(project_id, user_id, params) def perform(project_id)
begin begin
project = Project.unscoped.find(project_id) project = Project.unscoped.find(project_id)
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
...@@ -20,9 +20,6 @@ class NamespacelessProjectDestroyWorker ...@@ -20,9 +20,6 @@ class NamespacelessProjectDestroyWorker
end end
return unless project.namespace_id.nil? # Reject doing anything for projects that *do* have a namespace return unless project.namespace_id.nil? # Reject doing anything for projects that *do* have a namespace
user = User.find(user_id)
return unless user.can?(:remove_project, project)
project.team.truncate project.team.truncate
unlink_fork(project) if project.forked? unlink_fork(project) if project.forked?
......
...@@ -8,17 +8,14 @@ class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration ...@@ -8,17 +8,14 @@ class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration
disable_ddl_transaction! disable_ddl_transaction!
def up def up
admin = User.find_by(admin: true)
return unless admin
@offset = 0 @offset = 0
loop do loop do
ids = pending_delete_batch ids = pending_delete_batch
break if ids.rows.count.zero? break if ids.empty?
args = ids.map { |id| [id['id'], admin.id, {}] } args = ids.map { |id| Array(id) }
NamespacelessProjectDestroyWorker.bulk_perform_async(args) NamespacelessProjectDestroyWorker.bulk_perform_async(args)
...@@ -33,7 +30,7 @@ class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration ...@@ -33,7 +30,7 @@ class CleanupNamespacelessPendingDeleteProjects < ActiveRecord::Migration
private private
def pending_delete_batch def pending_delete_batch
connection.exec_query(find_batch) connection.exec_query(find_batch).map{ |row| row['id'] }
end end
BATCH_SIZE = 5000 BATCH_SIZE = 5000
......
...@@ -10,13 +10,21 @@ describe CleanupNamespacelessPendingDeleteProjects do ...@@ -10,13 +10,21 @@ describe CleanupNamespacelessPendingDeleteProjects do
describe '#up' do describe '#up' do
it 'only cleans up pending delete projects' do it 'only cleans up pending delete projects' do
admin = create(:admin)
create(:empty_project) create(:empty_project)
create(:empty_project, pending_delete: true) create(:empty_project, pending_delete: true)
project = build(:empty_project, pending_delete: true, namespace_id: nil) project = build(:empty_project, pending_delete: true, namespace_id: nil)
project.save(validate: false) project.save(validate: false)
expect(NamespacelessProjectDestroyWorker).to receive(:bulk_perform_async).with([[project.id.to_s, admin.id, {}]]) expect(NamespacelessProjectDestroyWorker).to receive(:bulk_perform_async).with([[project.id.to_s]])
described_class.new.up
end
it 'does nothing when no pending delete projects without namespace found' do
create(:empty_project)
create(:empty_project, pending_delete: true)
expect(NamespacelessProjectDestroyWorker).not_to receive(:bulk_perform_async)
described_class.new.up described_class.new.up
end end
......
...@@ -14,15 +14,13 @@ describe NamespacelessProjectDestroyWorker do ...@@ -14,15 +14,13 @@ describe NamespacelessProjectDestroyWorker do
it 'does not do anything' do it 'does not do anything' do
project = create(:empty_project) project = create(:empty_project)
subject.perform(project.id, project.owner.id, {}) subject.perform(project.id)
expect(Project.unscoped.all).to include(project) expect(Project.unscoped.all).to include(project)
end end
end end
context 'project has no namespace' do context 'project has no namespace' do
let(:admin) { create(:admin) }
let!(:project) do let!(:project) do
project = build(:empty_project, namespace_id: nil) project = build(:empty_project, namespace_id: nil)
project.save(validate: false) project.save(validate: false)
...@@ -33,11 +31,11 @@ describe NamespacelessProjectDestroyWorker do ...@@ -33,11 +31,11 @@ describe NamespacelessProjectDestroyWorker do
it "truncates the project's team" do it "truncates the project's team" do
expect_any_instance_of(ProjectTeam).to receive(:truncate) expect_any_instance_of(ProjectTeam).to receive(:truncate)
subject.perform(project.id, admin.id, {}) subject.perform(project.id)
end end
it 'deletes the project' do it 'deletes the project' do
subject.perform(project.id, admin.id, {}) subject.perform(project.id)
expect(Project.unscoped.all).not_to include(project) expect(Project.unscoped.all).not_to include(project)
end end
...@@ -45,13 +43,13 @@ describe NamespacelessProjectDestroyWorker do ...@@ -45,13 +43,13 @@ describe NamespacelessProjectDestroyWorker do
it 'does not call unlink_fork' do it 'does not call unlink_fork' do
is_expected.not_to receive(:unlink_fork) is_expected.not_to receive(:unlink_fork)
subject.perform(project.id, admin.id, {}) subject.perform(project.id)
end end
it 'does not do anything in Project#remove_pages method' do it 'does not do anything in Project#remove_pages method' do
expect(Gitlab::PagesTransfer).not_to receive(:new) expect(Gitlab::PagesTransfer).not_to receive(:new)
subject.perform(project.id, admin.id, {}) subject.perform(project.id)
end end
end end
...@@ -65,13 +63,13 @@ describe NamespacelessProjectDestroyWorker do ...@@ -65,13 +63,13 @@ describe NamespacelessProjectDestroyWorker do
it 'closes open merge requests' do it 'closes open merge requests' do
merge_request = create(:merge_request, source_project: project, target_project: parent_project) merge_request = create(:merge_request, source_project: project, target_project: parent_project)
subject.perform(project.id, admin.id, {}) subject.perform(project.id)
expect(merge_request.reload).to be_closed expect(merge_request.reload).to be_closed
end end
it 'destroys the link' do it 'destroys the link' do
subject.perform(project.id, admin.id, {}) subject.perform(project.id)
expect(parent_project.forked_project_links).to be_empty expect(parent_project.forked_project_links).to be_empty
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