Commit 4ded0411 authored by Jan Provaznik's avatar Jan Provaznik

Allow pass additional options to use_fast_destroy

These options are then used when setting before destroy callback.
parent 9ccf8d03
...@@ -76,8 +76,8 @@ module FastDestroyAll ...@@ -76,8 +76,8 @@ module FastDestroyAll
## ##
# This method is to be defined on models which have fast destroyable models as children, # This method is to be defined on models which have fast destroyable models as children,
# and let us avoid to use `dependent: :destroy` hook # and let us avoid to use `dependent: :destroy` hook
def use_fast_destroy(relation) def use_fast_destroy(relation, opts = {})
before_destroy(prepend: true) do set_callback :destroy, :before, opts.merge(prepend: true) do
perform_fast_destroy(public_send(relation)) # rubocop:disable GitlabSecurity/PublicSend perform_fast_destroy(public_send(relation)) # rubocop:disable GitlabSecurity/PublicSend
end end
end end
......
...@@ -31,13 +31,9 @@ module WithUploads ...@@ -31,13 +31,9 @@ module WithUploads
# TODO: when feature flag is removed, we can use just dependent: destroy # TODO: when feature flag is removed, we can use just dependent: destroy
# option on :file_uploads # option on :file_uploads
before_destroy :remove_file_uploads before_destroy :remove_file_uploads, unless: :fast_destroy_enabled?
use_fast_destroy :file_uploads use_fast_destroy :file_uploads, if: :fast_destroy_enabled?
end
def perform_fast_destroy(subject)
super if fast_destroy_enabled?
end end
def retrieve_upload(_identifier, paths) def retrieve_upload(_identifier, paths)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment