mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06: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:
@@ -18,7 +18,10 @@ class UserDestroyer
|
|||||||
raise PostsExistError if !opts[:delete_posts] && user.posts.count != 0
|
raise PostsExistError if !opts[:delete_posts] && user.posts.count != 0
|
||||||
@guardian.ensure_can_delete_user!(user)
|
@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
|
Draft.where(user_id: user.id).delete_all
|
||||||
QueuedPost.where(user_id: user.id).delete_all
|
QueuedPost.where(user_id: user.id).delete_all
|
||||||
@@ -106,4 +109,14 @@ class UserDestroyer
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def optional_transaction(open_transaction: true)
|
||||||
|
if open_transaction
|
||||||
|
User.transaction { yield }
|
||||||
|
else
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user