Просмотр исходного кода

fix #907: removed excessive lock calls from codebase

Rafał Pitoń 7 лет назад
Родитель
Сommit
a5fdc9b726

+ 5 - 0
misago/threads/api/threadendpoints/read.py

@@ -1,3 +1,4 @@
+from django.db import transaction
 from django.shortcuts import get_object_or_404
 
 from misago.categories import THREADS_ROOT_NAME
@@ -8,6 +9,7 @@ from misago.readtracker.categoriestracker import read_category
 from misago.threads.threadtypes import trees_map
 
 
+@transaction.atomic
 def read_threads(user, pk):
     user.lock()
 
@@ -27,7 +29,10 @@ def read_threads(user, pk):
     read_category(user, category)
 
 
+@transaction.atomic
 def read_private_threads(user):
+    user.lock()
+
     category = Category.objects.private_threads()
     read_category(user, category)
 

+ 0 - 8
misago/threads/api/threadpoll.py

@@ -45,8 +45,6 @@ class ViewSet(viewsets.ViewSet):
 
     @transaction.atomic
     def create(self, request, thread_pk):
-        request.user.lock()
-
         thread = self.get_thread(request, thread_pk)
         allow_start_poll(request.user, thread)
 
@@ -82,8 +80,6 @@ class ViewSet(viewsets.ViewSet):
 
     @transaction.atomic
     def update(self, request, thread_pk, pk=None):
-        request.user.lock()
-
         thread = self.get_thread(request, thread_pk)
         instance = self.get_poll(thread, pk)
 
@@ -102,8 +98,6 @@ class ViewSet(viewsets.ViewSet):
 
     @transaction.atomic
     def delete(self, request, thread_pk, pk=None):
-        request.user.lock()
-
         thread = self.get_thread(request, thread_pk)
         instance = self.get_poll(thread, pk)
 
@@ -127,8 +121,6 @@ class ViewSet(viewsets.ViewSet):
 
     @transaction.atomic
     def post_votes(self, request, thread_pk, pk=None):
-        request.user.lock()
-
         thread = self.get_thread(request, thread_pk)
         instance = self.get_poll(thread, pk)
 

+ 0 - 3
misago/threads/api/threads.py

@@ -48,7 +48,6 @@ class ViewSet(viewsets.ViewSet):
 
     @transaction.atomic
     def partial_update(self, request, pk=None):
-        request.user.lock()
         thread = self.get_thread(request, pk).unwrap()
         return thread_patch_endpoint(request, thread)
 
@@ -111,7 +110,6 @@ class ThreadViewSet(ViewSet):
         return thread_start_editor(request)
 
     @list_route(methods=['post'])
-    @transaction.atomic
     def read(self, request):
         read_threads(request.user, request.GET.get('category'))
         return Response({})
@@ -157,7 +155,6 @@ class PrivateThreadViewSet(ViewSet):
             return Response(posting.errors, status=400)
 
     @list_route(methods=['post'])
-    @transaction.atomic
     def read(self, request):
         allow_use_private_threads(request.user)
         read_private_threads(request.user)