diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-20 18:40:28 +0300 |
commit | b595cb0c1dec83de5bdee18284abe86614bed33b (patch) | |
tree | 8c3d4540f193c5ff98019352f554e921b3a41a72 /app/services/projects/destroy_service.rb | |
parent | 2f9104a328fc8a4bddeaa4627b595166d24671d0 (diff) |
Add latest changes from gitlab-org/gitlab@15-2-stable-eev15.2.0-rc42
Diffstat (limited to 'app/services/projects/destroy_service.rb')
-rw-r--r-- | app/services/projects/destroy_service.rb | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/app/services/projects/destroy_service.rb b/app/services/projects/destroy_service.rb index bc5be5bdff3..06a44b07f9f 100644 --- a/app/services/projects/destroy_service.rb +++ b/app/services/projects/destroy_service.rb @@ -132,7 +132,7 @@ module Projects destroy_web_hooks! destroy_project_bots! destroy_ci_records! - destroy_mr_diff_commits! + destroy_mr_diff_relations! # Rails attempts to load all related records into memory before # destroying: https://github.com/rails/rails/issues/22510 @@ -153,23 +153,28 @@ module Projects # cascading deletes may exceed statement timeouts, causing failures. # (see https://gitlab.com/gitlab-org/gitlab/-/issues/346166) # + # Removing merge_request_diff_files records may also cause timeouts, so they + # can be deleted in batches as well. + # # rubocop: disable CodeReuse/ActiveRecord - def destroy_mr_diff_commits! + def destroy_mr_diff_relations! mr_batch_size = 100 delete_batch_size = 1000 project.merge_requests.each_batch(column: :iid, of: mr_batch_size) do |relation_ids| - loop do - inner_query = MergeRequestDiffCommit - .select(:merge_request_diff_id, :relative_order) - .where(merge_request_diff_id: MergeRequestDiff.where(merge_request_id: relation_ids).select(:id)) - .limit(delete_batch_size) - - deleted_rows = MergeRequestDiffCommit - .where('(merge_request_diff_commits.merge_request_diff_id, merge_request_diff_commits.relative_order) IN (?)', inner_query) - .delete_all - - break if deleted_rows == 0 + [MergeRequestDiffCommit, MergeRequestDiffFile].each do |model| + loop do + inner_query = model + .select(:merge_request_diff_id, :relative_order) + .where(merge_request_diff_id: MergeRequestDiff.where(merge_request_id: relation_ids).select(:id)) + .limit(delete_batch_size) + + deleted_rows = model + .where("(#{model.table_name}.merge_request_diff_id, #{model.table_name}.relative_order) IN (?)", inner_query) # rubocop:disable GitlabSecurity/SqlInjection + .delete_all + + break if deleted_rows == 0 + end end end end @@ -212,7 +217,7 @@ module Projects # produces smaller and faster queries to the database. def destroy_web_hooks! project.hooks.find_each do |web_hook| - result = ::WebHooks::DestroyService.new(current_user).sync_destroy(web_hook) + result = ::WebHooks::DestroyService.new(current_user).execute(web_hook) unless result[:status] == :success raise_error(s_('DeleteProject|Failed to remove webhooks. Please try again or contact administrator.')) @@ -263,8 +268,12 @@ module Projects end def publish_project_deleted_event_for(project) - data = { project_id: project.id, namespace_id: project.namespace_id } - event = Projects::ProjectDeletedEvent.new(data: data) + event = Projects::ProjectDeletedEvent.new(data: { + project_id: project.id, + namespace_id: project.namespace_id, + root_namespace_id: project.root_namespace.id + }) + Gitlab::EventStore.publish(event) end end |