Browse Source

small performace tweaks

Rafał Pitoń 8 years ago
parent
commit
238f891628

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

@@ -1,5 +1,7 @@
+from django.core.exceptions import PermissionDenied
 from django.db import transaction
 from django.db import transaction
 from django.http import Http404
 from django.http import Http404
+from django.utils.translation import gettext as _
 
 
 from rest_framework import viewsets
 from rest_framework import viewsets
 from rest_framework.decorators import detail_route
 from rest_framework.decorators import detail_route
@@ -49,6 +51,12 @@ class ViewSet(viewsets.ViewSet):
         thread = self.get_thread_for_update(request, thread_pk)
         thread = self.get_thread_for_update(request, thread_pk)
         allow_start_poll(request.user, thread)
         allow_start_poll(request.user, thread)
 
 
+        try:
+            if thread.poll and thread.poll.pk:
+                raise PermissionDenied(_("There's already a poll in this thread."))
+        except Poll.DoesNotExist:
+            pass
+
         instance = Poll(
         instance = Poll(
             thread=thread,
             thread=thread,
             category=thread.category,
             category=thread.category,

+ 0 - 5
misago/threads/permissions/polls.py

@@ -130,11 +130,6 @@ def allow_start_poll(user, target):
             raise PermissionDenied(_("This category is closed. You can't start polls in it."))
             raise PermissionDenied(_("This category is closed. You can't start polls in it."))
         if target.is_closed:
         if target.is_closed:
             raise PermissionDenied(_("This thread is closed. You can't start polls in it."))
             raise PermissionDenied(_("This thread is closed. You can't start polls in it."))
-    try:
-        if target.poll and target.poll.pk:
-            raise PermissionDenied(_("There's already a poll in this thread."))
-    except Poll.DoesNotExist:
-        pass
 can_start_poll = return_boolean(allow_start_poll)
 can_start_poll = return_boolean(allow_start_poll)
 
 
 
 

+ 1 - 0
misago/threads/viewmodels/threads.py

@@ -67,6 +67,7 @@ class ViewModel(object):
             threadstracker.make_threads_read_aware(request.user, threads)
             threadstracker.make_threads_read_aware(request.user, threads)
 
 
         add_categories_to_items(category_model, category.categories, threads)
         add_categories_to_items(category_model, category.categories, threads)
+
         add_acl(request.user, threads)
         add_acl(request.user, threads)
         make_subscription_aware(request.user, threads)
         make_subscription_aware(request.user, threads)
 
 

+ 1 - 1
misago/users/viewmodels/threads.py

@@ -67,7 +67,7 @@ class UserThreads(object):
             request.user, threads_categories, profile.thread_set)
             request.user, threads_categories, profile.thread_set)
 
 
     def get_posts_queryset(self, user, profile, threads_queryset):
     def get_posts_queryset(self, user, profile, threads_queryset):
-        return profile.post_set.select_related('thread', 'thread__poll').filter(
+        return profile.post_set.select_related('thread').filter(
             id__in=threads_queryset.values('first_post_id')
             id__in=threads_queryset.values('first_post_id')
         )
         )
 
 

+ 3 - 1
misago/users/views/profile.py

@@ -12,7 +12,8 @@ from django.utils.translation import ugettext as _
 
 
 from misago.acl import add_acl
 from misago.acl import add_acl
 from misago.core.decorators import require_POST
 from misago.core.decorators import require_POST
-from misago.core.shortcuts import get_object_or_404, paginate, pagination_dict, validate_slug
+from misago.core.shortcuts import (
+    get_object_or_404, paginate, pagination_dict, validate_slug)
 from misago.core.utils import clean_return_path
 from misago.core.utils import clean_return_path
 from misago.threads.permissions import allow_message_user
 from misago.threads.permissions import allow_message_user
 
 
@@ -33,6 +34,7 @@ def profile_view(f):
 
 
         relations = ('rank', 'online_tracker', 'ban_cache')
         relations = ('rank', 'online_tracker', 'ban_cache')
         queryset = User.objects.select_related(*relations)
         queryset = User.objects.select_related(*relations)
+
         profile = get_object_or_404(queryset, pk=kwargs.pop('pk'))
         profile = get_object_or_404(queryset, pk=kwargs.pop('pk'))
 
 
         validate_slug(profile, kwargs.pop('slug'))
         validate_slug(profile, kwargs.pop('slug'))