diff options
Diffstat (limited to 'app/services/projects/destroy_service.rb')
-rw-r--r-- | app/services/projects/destroy_service.rb | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/app/services/projects/destroy_service.rb b/app/services/projects/destroy_service.rb index 37487261f2c..bec75657530 100644 --- a/app/services/projects/destroy_service.rb +++ b/app/services/projects/destroy_service.rb @@ -28,7 +28,7 @@ module Projects Projects::UnlinkForkService.new(project, current_user).execute - attempt_destroy_transaction(project) + attempt_destroy(project) system_hook_service.execute_hooks_for(project, :destroy) log_info("Project \"#{project.full_path}\" was deleted") @@ -98,29 +98,35 @@ module Projects log_error("Deletion failed on #{project.full_path} with the following message: #{message}") end - def attempt_destroy_transaction(project) + def attempt_destroy(project) unless remove_registry_tags raise_error(s_('DeleteProject|Failed to remove some tags in project container registry. Please try again or contact administrator.')) end project.leave_pool_repository - Project.transaction do - log_destroy_event - trash_relation_repositories! - trash_project_repositories! - - # Rails attempts to load all related records into memory before - # destroying: https://github.com/rails/rails/issues/22510 - # This ensures we delete records in batches. - # - # Exclude container repositories because its before_destroy would be - # called multiple times, and it doesn't destroy any database records. - project.destroy_dependent_associations_in_batches(exclude: [:container_repositories, :snippets]) - project.destroy! + if Gitlab::Ci::Features.project_transactionless_destroy?(project) + destroy_project_related_records(project) + else + Project.transaction { destroy_project_related_records(project) } end end + def destroy_project_related_records(project) + log_destroy_event + trash_relation_repositories! + trash_project_repositories! + + # Rails attempts to load all related records into memory before + # destroying: https://github.com/rails/rails/issues/22510 + # This ensures we delete records in batches. + # + # Exclude container repositories because its before_destroy would be + # called multiple times, and it doesn't destroy any database records. + project.destroy_dependent_associations_in_batches(exclude: [:container_repositories, :snippets]) + project.destroy! + end + def log_destroy_event log_info("Attempting to destroy #{project.full_path} (#{project.id})") end |