Implement Ci::DeletedObject for PipelineArtifacts
Problem
We need to unify Artfifacts (Job/Pipeline) removal by leveraging Ci::DeletedObject.
In #270973 (closed) we have moved the removal of expired pipeline artifacts into a new service but they are still removed one by one. We should implement the interface needed to use Ci::DeletedObject for their removal:
Solution
-
Abstract #to_deleted_object_attrs to Artifactable so it will also be defined for PipelineArtifact
-
Change the service to bulk insert deleted objects and mass delete pipeline artifacts with a single SQL query, like we do for job artifacts.
diff --git a/app/services/ci/pipeline_artifacts/destroy_all_expired_service.rb b/app/services/ci/pipeline_artifacts/destroy_all_expired_service.rb
index 7b6590a117c..30ef011b9ed 100644
--- a/app/services/ci/pipeline_artifacts/destroy_all_expired_service.rb
+++ b/app/services/ci/pipeline_artifacts/destroy_all_expired_service.rb
@@ -28,7 +28,11 @@ def destroy_artifacts_batch
artifacts = ::Ci::PipelineArtifact.unlocked.expired(BATCH_SIZE).to_a
return false if artifacts.empty?
- artifacts.each(&:destroy!)
+ Ci::DeletedObject.transaction do
+ Ci::DeletedObject.bulk_import(artifacts, Time.current)
+ Ci::PipelineArtifact.id_in(artifacts.map(&:id)).delete_all
+ end
+
increment_stats(artifacts.size)
true
-
Handle all the after_destroy/commit
callbacks, like updating project statistics and the updates for geo.
Edited by Max Orefice