ActsAsParanoid / acts_as_paranoid

ActiveRecord plugin allowing you to hide and restore records without actually deleting them.
MIT License
1.47k stars 192 forks source link

destroy_fully! does not perform real deletion at once. Performance issue. #203

Open pilgunboris opened 3 years ago

pilgunboris commented 3 years ago

Hello! I have a huge performance issue when trying to rollback a big data import and calling destroy_fully! on each ActiveRecord instance with acts_as_paranoid support. Each instance has multiple soft-deletable associations with dependeng: :destroy options. This whole process is unacceptably slow and one of the reasons (except slow AR by itself) is that destroy_fully! doesn't really destroy the resource and associations at once but at first it soft-deletes them and then makes real full deletion as a second round. Is there any way to make this a single-round process and destroy them at once just like it would be in pure Rails?

Similarly to how we can disable touching of the associations just for a block of code:

ActiveRecord::Base.no_touching do
  ...
end

If it is not possible yet then maybe it can be added as a new feature? Or might be something that will just disable acts_as_paranoid completely inside of a specified block of code? Will it be possible to only decrease dependent cache_counters in such case if any?

Thanks!