mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 18:05:31 +08:00
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:
parent
bee68bba2e
commit
6079a3e4d0
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user