Browse Source

#472: changed forum locks

Rafał Pitoń 10 years ago
parent
commit
79d94368d4

+ 14 - 11
misago/threads/views/generic/forum/actions.py

@@ -188,11 +188,13 @@ class ForumActions(Actions):
             if form.is_valid():
             if form.is_valid():
                 new_forum = form.cleaned_data['new_forum']
                 new_forum = form.cleaned_data['new_forum']
                 with atomic():
                 with atomic():
-                    self.forum.lock()
 
 
                     for thread in threads:
                     for thread in threads:
                         moderation.move_thread(request.user, thread, new_forum)
                         moderation.move_thread(request.user, thread, new_forum)
 
 
+                    self.forum.lock()
+                    new_forum.lock()
+
                     self.forum.synchronize()
                     self.forum.synchronize()
                     self.forum.save()
                     self.forum.save()
                     new_forum.synchronize()
                     new_forum.synchronize()
@@ -259,7 +261,7 @@ class ForumActions(Actions):
                     merged_thread.synchronize()
                     merged_thread.synchronize()
                     merged_thread.save()
                     merged_thread.save()
 
 
-                with atomic():
+                    self.forum.lock()
                     self.forum.synchronize()
                     self.forum.synchronize()
                     self.forum.save()
                     self.forum.save()
 
 
@@ -327,6 +329,7 @@ class ForumActions(Actions):
 
 
         if changed_threads:
         if changed_threads:
             with atomic():
             with atomic():
+                self.forum.lock()
                 self.forum.synchronize()
                 self.forum.synchronize()
                 self.forum.save()
                 self.forum.save()
 
 
@@ -341,13 +344,13 @@ class ForumActions(Actions):
 
 
     def action_hide(self, request, threads):
     def action_hide(self, request, threads):
         changed_threads = 0
         changed_threads = 0
-        with atomic():
-            self.forum.lock()
-            for thread in threads:
-                if moderation.hide_thread(request.user, thread):
-                    changed_threads += 1
+        for thread in threads:
+            if moderation.hide_thread(request.user, thread):
+                changed_threads += 1
 
 
-            if changed_threads:
+        if changed_threads:
+            with atomic():
+                self.forum.lock()
                 self.forum.synchronize()
                 self.forum.synchronize()
                 self.forum.save()
                 self.forum.save()
 
 
@@ -363,13 +366,13 @@ class ForumActions(Actions):
 
 
     def action_delete(self, request, threads):
     def action_delete(self, request, threads):
         changed_threads = 0
         changed_threads = 0
-        with atomic():
-            self.forum.lock()
             for thread in threads:
             for thread in threads:
                 if moderation.delete_thread(request.user, thread):
                 if moderation.delete_thread(request.user, thread):
                     changed_threads += 1
                     changed_threads += 1
 
 
-            if changed_threads:
+        if changed_threads:
+            with atomic():
+                self.forum.lock()
                 self.forum.synchronize()
                 self.forum.synchronize()
                 self.forum.save()
                 self.forum.save()
 
 

+ 2 - 1
misago/threads/views/generic/thread/postsactions.py

@@ -15,7 +15,6 @@ __all__ = ['PostsActions']
 def atomic_post_action(f):
 def atomic_post_action(f):
     def decorator(self, request, posts):
     def decorator(self, request, posts):
         with atomic():
         with atomic():
-            self.forum.lock()
             self.thread.lock()
             self.thread.lock()
 
 
             for post in posts:
             for post in posts:
@@ -25,6 +24,8 @@ def atomic_post_action(f):
 
 
             self.thread.synchronize()
             self.thread.synchronize()
             self.thread.save()
             self.thread.save()
+
+            self.forum.lock()
             self.forum.synchronize()
             self.forum.synchronize()
             self.forum.save()
             self.forum.save()
 
 

+ 4 - 1
misago/threads/views/generic/thread/threadactions.py

@@ -146,8 +146,11 @@ class ThreadActions(ActionsBase):
                 new_forum = form.cleaned_data['new_forum']
                 new_forum = form.cleaned_data['new_forum']
 
 
                 with atomic():
                 with atomic():
-                    self.forum.lock()
                     moderation.move_thread(request.user, thread, new_forum)
                     moderation.move_thread(request.user, thread, new_forum)
+
+                    self.forum.lock()
+                    new_forum.lock()
+
                     self.forum.synchronize()
                     self.forum.synchronize()
                     self.forum.save()
                     self.forum.save()
                     new_forum.synchronize()
                     new_forum.synchronize()

+ 4 - 0
misago/threads/views/post.py

@@ -61,6 +61,8 @@ class QuotePostView(PostView):
 
 
 
 
 class UnhidePostView(PostView):
 class UnhidePostView(PostView):
+    is_atomic = False
+
     def real_dispatch(self, request, post):
     def real_dispatch(self, request, post):
         permissions.allow_unhide_post(request.user, post)
         permissions.allow_unhide_post(request.user, post)
         moderation.unhide_post(request.user, post)
         moderation.unhide_post(request.user, post)
@@ -68,6 +70,8 @@ class UnhidePostView(PostView):
 
 
 
 
 class HidePostView(PostView):
 class HidePostView(PostView):
+    is_atomic = False
+
     def real_dispatch(self, request, post):
     def real_dispatch(self, request, post):
         permissions.allow_hide_post(request.user, post)
         permissions.allow_hide_post(request.user, post)
         moderation.hide_post(request.user, post)
         moderation.hide_post(request.user, post)