A Rails gem that destroys records and their dependent: :destroy trees with set-based SQL while still running every destroy callback, including the children's.
delete_all is fast but skips callbacks. destroy_all runs every callback but loads each record and deletes it with its own query, and does the same for every child. On a tree with a few thousand parents and tens of thousands of children, that is tens of thousands of queries.
I wanted both: every before_destroy , around_destroy and after_destroy hook, on every record in the tree, with bulk SQL underneath. So I built bulk_destroyer .
Post . where ( author_id: 42 ). bulk_destroy_all post . bulk_destroy!
Enter fullscreen mode
Exit fullscreen mode
What you get
Per batch, it issues one SELECT per association per level and one DELETE per table per level.β¦