Browse Source

Tweaked transaction isolation in user deletion

Rafał Pitoń 10 years ago
parent
commit
a16b939bc3
2 changed files with 7 additions and 2 deletions
  1. 5 2
      misago/threads/signals.py
  2. 2 0
      misago/users/views/admin/users.py

+ 5 - 2
misago/threads/signals.py

@@ -1,3 +1,4 @@
+from django.db import transaction
 from django.dispatch import receiver, Signal
 
 from misago.core.pgutils import batch_update, batch_delete
@@ -50,12 +51,14 @@ def delete_user_threads(sender, **kwargs):
 
     for thread in batch_delete(sender.thread_set.all(), 50):
         recount_forums.add(thread.forum_id)
-        thread.delete()
+        with transaction.atomic():
+            thread.delete()
 
     for post in batch_delete(sender.post_set.all(), 50):
         recount_forums.add(post.forum_id)
         recount_threads.add(post.thread_id)
-        post.delete()
+        with transaction.atomic():
+            post.delete()
 
     if recount_threads:
         changed_threads_qs = Thread.objects.filter(id__in=recount_threads)

+ 2 - 0
misago/users/views/admin/users.py

@@ -1,5 +1,6 @@
 from django.contrib import messages
 from django.contrib.auth import get_user_model, update_session_auth_hash
+from django.db import transaction
 from django.shortcuts import redirect
 from django.utils.translation import ugettext_lazy as _
 
@@ -70,6 +71,7 @@ class UsersList(UserAdmin, generic.ListView):
             'confirmation': _("Are you sure you want to delete selected "
                               "users? This will also delete all content "
                               "associated with their accounts."),
+            'is_atomic': False,
         }
     ]