Class: Projects::ImportExport::RemoveRelationExportUploadsService
- Inherits:
-
Object
- Object
- Projects::ImportExport::RemoveRelationExportUploadsService
- Defined in:
- app/services/projects/import_export/remove_relation_export_uploads_service.rb
Overview
When a project is deleted, database-level ‘ON DELETE CASCADE` then removes all records in the hierarchy down to and including Projects::ImportExport::RelationExportUpload. There is no FK relation between RelationExportUpload and Upload records, so those must be cleaned up at the code level. We can leave the other records (Projects::ImportExport::RelationExport, etc.) intact, as they will be removed by the FK cascade.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(project) ⇒ RemoveRelationExportUploadsService
constructor
A new instance of RemoveRelationExportUploadsService.
Constructor Details
#initialize(project) ⇒ RemoveRelationExportUploadsService
Returns a new instance of RemoveRelationExportUploadsService.
13 14 15 |
# File 'app/services/projects/import_export/remove_relation_export_uploads_service.rb', line 13 def initialize(project) @project = project end |
Instance Method Details
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/projects/import_export/remove_relation_export_uploads_service.rb', line 17 def execute relation_export_uploads.each_batch do |batch| batch.includes(:uploads).find_each do |relation_export_upload| # rubocop:disable CodeReuse/ActiveRecord -- small dataset # As `Projects::ImportExport::RelationExportUpload` will be removed # by the foreign key cascade, we can't rely on it still existing by # the time this job executes. Consequently, we find and pass each # upload ID. relation_export_upload.uploads.find_each do |upload| ::Projects::ImportExport::RemoveRelationExportUploadWorker.perform_async(upload.id) end end end ServiceResponse.success end |