diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-02-12 15:37:11 +0000 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-02-12 15:37:11 +0000 |
commit | da1aaaf2e56a6ed516e603a5a22044d89f61b0c0 (patch) | |
tree | 259086405076a671d7c39a82b0cff4652196ed97 | |
parent | 3dcdf16fbad67e64adc2db232bb11391586b3972 (diff) | |
parent | c3782d20afc421cee972df0fa26e9a8e67210f52 (diff) | |
download | gitlab-ce-da1aaaf2e56a6ed516e603a5a22044d89f61b0c0.tar.gz |
Merge branch 'remove-fast-destroy-flag' into 'master'
Remove fast_destroy_uploads feature flag
Closes #54937
See merge request gitlab-org/gitlab-ce!24930
-rw-r--r-- | app/models/concerns/with_uploads.rb | 34 | ||||
-rw-r--r-- | changelogs/unreleased/fast-destroy-uploads.yml | 5 | ||||
-rw-r--r-- | spec/support/shared_examples/models/with_uploads_shared_examples.rb | 20 |
3 files changed, 9 insertions, 50 deletions
diff --git a/app/models/concerns/with_uploads.rb b/app/models/concerns/with_uploads.rb index d79c0eae77e..6c6febd186c 100644 --- a/app/models/concerns/with_uploads.rb +++ b/app/models/concerns/with_uploads.rb @@ -27,40 +27,14 @@ module WithUploads included do has_many :uploads, as: :model - has_many :file_uploads, -> { where(uploader: FILE_UPLOADERS) }, class_name: 'Upload', as: :model + has_many :file_uploads, -> { where(uploader: FILE_UPLOADERS) }, + class_name: 'Upload', as: :model, + dependent: :delete_all # rubocop:disable Cop/ActiveRecordDependent - # TODO: when feature flag is removed, we can use just dependent: destroy - # option on :file_uploads - before_destroy :remove_file_uploads - - use_fast_destroy :file_uploads, if: :fast_destroy_enabled? + use_fast_destroy :file_uploads end def retrieve_upload(_identifier, paths) uploads.find_by(path: paths) end - - private - - # 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 remove_file_uploads - fast_destroy_enabled? ? delete_uploads : destroy_uploads - end - - def delete_uploads - file_uploads.delete_all(:delete_all) - end - - def destroy_uploads - file_uploads.find_each do |upload| - upload.destroy - end - end - - def fast_destroy_enabled? - Feature.enabled?(:fast_destroy_uploads, self) - end end diff --git a/changelogs/unreleased/fast-destroy-uploads.yml b/changelogs/unreleased/fast-destroy-uploads.yml new file mode 100644 index 00000000000..ee3363a6ae9 --- /dev/null +++ b/changelogs/unreleased/fast-destroy-uploads.yml @@ -0,0 +1,5 @@ +--- +title: File uploads are deleted asynchronously when deleting a project or group. +merge_request: +author: +type: added diff --git a/spec/support/shared_examples/models/with_uploads_shared_examples.rb b/spec/support/shared_examples/models/with_uploads_shared_examples.rb index 1d11b855459..43033a2d256 100644 --- a/spec/support/shared_examples/models/with_uploads_shared_examples.rb +++ b/spec/support/shared_examples/models/with_uploads_shared_examples.rb @@ -44,26 +44,6 @@ shared_examples_for 'model with uploads' do |supports_fileuploads| model_object.destroy end end - - describe 'destroy strategy depending on feature flag' do - let!(:upload) { create(:upload, uploader: FileUploader, model: model_object) } - - it 'does not destroy uploads by default' do - expect(model_object).to receive(:delete_uploads) - expect(model_object).not_to receive(:destroy_uploads) - - model_object.destroy - end - - it 'uses before destroy callback if feature flag is disabled' do - stub_feature_flags(fast_destroy_uploads: false) - - expect(model_object).to receive(:destroy_uploads) - expect(model_object).not_to receive(:delete_uploads) - - model_object.destroy - end - end end end end |