Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

deduplicate file_links deletion mechanism

Christophe Bliard98e57284ff71
diff --git a/modules/storages/app/services/storages/project_storages/delete_service.rb b/modules/storages/app/services/storages/project_storages/delete_service.rb
index 0eb4a553318..19625639897 100644
--- a/modules/storages/app/services/storages/project_storages/delete_service.rb
+++ b/modules/storages/app/services/storages/project_storages/delete_service.rb
@@ -27,33 +27,8 @@
#++
module Storages::ProjectStorages
+ # Performs the deletion in the superclass. Associated FileLinks are deleted
+ # by the model before_destroy hook.
class DeleteService < ::BaseServices::Delete
- # "persist" is a callback from BaseContracted.perform
- # that is supposed to do the actual work in a contract.
- # So in a DeleteService it performs the actual delete,
- # except for the @object.destroy that is already performed
- # by ::BaseServices::Delete
- def persist(service_result)
- # Perform the @object.destroy etc. in the super-class
- super(service_result).tap do |deletion_result|
- delete_associated_file_links if deletion_result.success?
- end
- end
-
- private
-
- # Delete FileLinks with the same Storage as the ProjectStorage.
- # Also, they are attached to WorkPackages via the Project.
- def delete_associated_file_links
- # work_packages is an ActiveRecord::Relation, not an array of objects!
- work_packages = WorkPackage.where(project_id: model.project_id)
- file_links = Storages::FileLink.where(storage_id: model.storage_id,
- container: work_packages)
- # use file_links.to_sql to check the SQL generated by the lines above.
- # It uses a fast SQL "container_id in (select * from work_packages...)", so the
- # delete_all below is executed using a single query.
- # Reference: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html
- file_links.delete_all
- end
end
end