Follow-up from "Delete remote uploads"
Currently we use 2 different versions of uploads:
- mounted - deletion is handled by carrierwave's after_Commit destroy hook
- not-mounted - we delete these uploads when deleting "parent's" model
The problem is that both versions have exactly opposite requirements about order of destroying resources and we can not destroy all types of uplaods in after_commit
hook currently. We should figure out how to break cyclic resource dependency for both versions of uploads so both versions can be deleted in after_commit
hook.
The following discussions from !18698 (merged) should be addressed:
-
@mbergeron started a discussion: (+2 comments) The only concern I have in a
before_destroy
hook is that there is no way to rollback the file destruction in case of rollback of thedestroy
. I wonder if we could serialize the whole record in a background job and schedule it to run in aafter_commit ... on: destroy
, so that we are sure the destruction actually happened. -
@mbergeron started a discussion: (+3 comments) it can not be done in after_commit because FileUploader requires loads associated model
The associated model is
self
I think that is still available, even though it is marked asdeleted
, for the duration of the hook. Isn't it?self.uploads.first.model == self -> True
, right?
EDIT: It seems that !18575 (merged) (which has been merged just few days ago)might be a good fit for solving the follow-up issue with using before_destroy hook - #46069 (closed). We will still have to get rid of "build_uploader" method called on destroy which requires whole destroyed model (ideally we would need just path/key).