FEATURE: allow calling user destroyer without a transaction

This additional option allows us to destroy a user in "pieces" in cases
where database is very big and stuff tends to time out
This commit is contained in:
Sam 2019-01-17 07:54:21 +11:00
parent bee68bba2e
commit 6079a3e4d0

View File

@ -18,7 +18,10 @@ class UserDestroyer
raise PostsExistError if !opts[:delete_posts] && user.posts.count != 0
@guardian.ensure_can_delete_user!(user)
User.transaction do
# default to using a transaction
opts[:transaction] = true if opts[:transaction] != false
optional_transaction(open_transaction: opts[:transaction]) do
Draft.where(user_id: user.id).delete_all
QueuedPost.where(user_id: user.id).delete_all
@ -106,4 +109,14 @@ class UserDestroyer
end
end
protected
def optional_transaction(open_transaction: true)
if open_transaction
User.transaction { yield }
else
yield
end
end
end