Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2018-10-07 21:31:08 +0300
committerJan Provaznik <jprovaznik@gitlab.com>2018-12-07 00:00:19 +0300
commit239fdc78b1ced1861cdcf00b8927963e30ef2095 (patch)
treef5888314cdedf47b21a259d334fc739be0e38d5a /app/models/concerns/with_uploads.rb
parentc3bbad762d418857e3f5b52222f5eedd62663229 (diff)
Use FastDestroy for deleting uploads
It gathers list of file paths to delete before destroying the parent object. Then after the parent_object is destroyed these paths are scheduled for deletion asynchronously. Carrierwave needed associated model for deleting upload file. To avoid this requirement, simple Fog/File layer is used directly for file deletion, this allows us to use just a simple list of paths.
Diffstat (limited to 'app/models/concerns/with_uploads.rb')
-rw-r--r--app/models/concerns/with_uploads.rb14
1 files changed, 3 insertions, 11 deletions
diff --git a/app/models/concerns/with_uploads.rb b/app/models/concerns/with_uploads.rb
index 2bdef2a40e4..50a9b19299a 100644
--- a/app/models/concerns/with_uploads.rb
+++ b/app/models/concerns/with_uploads.rb
@@ -17,6 +17,7 @@
module WithUploads
extend ActiveSupport::Concern
+ include FastDestroyAll::Helpers
# Currently there is no simple way how to select only not-mounted
# uploads, it should be all FileUploaders so we select them by
@@ -25,18 +26,9 @@ module WithUploads
included do
has_many :uploads, as: :model
+ has_many :file_uploads, -> { where(uploader: FILE_UPLOADERS) }, class_name: 'Upload', as: :model, dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent
- before_destroy :destroy_file_uploads
- end
-
- # mounted uploads are deleted in carrierwave's after_commit hook,
- # but FileUploaders which are not mounted must be deleted explicitly and
- # it can not be done in after_commit because FileUploader requires loads
- # associated model on destroy (which is already deleted in after_commit)
- def destroy_file_uploads
- self.uploads.where(uploader: FILE_UPLOADERS).find_each do |upload|
- upload.destroy
- end
+ use_fast_destroy :file_uploads
end
def retrieve_upload(_identifier, paths)