You want your soft_delete to be tracked as a boolean flag in all relevant entries. Set default areas to return only records that do not have the flag set. When the time comes to activate or deactivate, collect all your relevant entries and click them with update_all . Here, the example starts with 13,000 user records to give you a sense of time and performance:
1.9.2p320 :001 > User.update_all(soft_deleted: false) SQL (1016.3ms) UPDATE "users" SET "soft_deleted" = 'f' => 13350
As you can see, he hit all 13,000 records so that this flag switches for about one second. So, if you want to hit the user, all messages of the user and all users of PrivateMessages,
User.update_attributes(soft_deleted: true) User.posts.update_all(soft_deleted: true) User.private_messages.update_all(soft_deleted: true)
And you should be good to go. If you deal with so many entries that even this technique doesnβt work well, I donβt think you will have much choice but to tell the user what might be a few minutes before all their data is available for reactivation and throw the whole process into a background task as you originally planned.
source share