Commit 90df9a55c8b4b5dcd989a8f4520aa7526354091e

Authored by Andrew Buss
1 parent 5c1348fee8
Exists in master

django-debug-toolbar; performance improvements

Showing 3 changed files with 15 additions and 3 deletions Side-by-side Diff

flashcards/models.py View file @ 90df9a5
... ... @@ -25,6 +25,10 @@
25 25  
26 26  
27 27  
  28 +
  29 +
  30 +
  31 +
28 32 # Hack to fix AbstractUser before subclassing it
29 33  
30 34 AbstractUser._meta.get_field('email')._unique = True
... ... @@ -316,6 +320,7 @@
316 320 :param user:
317 321 :return: Whether the card is hidden from the user.
318 322 """
  323 + if self.is_not_hidden: return False
319 324 return self.is_hidden or self.flashcardhide_set.filter(user=user).exists()
320 325  
321 326 def is_in_deck(self, user):
... ... @@ -395,8 +400,12 @@
395 400 :param user:
396 401 :return: A queryset with all cards that should be visible to a user.
397 402 """
398   - return cls.objects.filter(Q(author__confirmed_email=True) | Q(author=user)
399   - ).exclude(Q(is_hidden=True) | Q(flashcardhide__user=user))
  403 + # All flashcards where the author is either confirmed, or the user
  404 + rqs = cls.objects.filter(Q(author__confirmed_email=True) | Q(author=user))
  405 + # Exclude hidden cards
  406 + rqs = rqs.exclude(Q(is_hidden=True) | Q(flashcardhide__user=user))
  407 + # Annotate the cards so we don't have to check if they're hidden in the future
  408 + return rqs.annotate(is_not_hidden=Value(True, output_field=BooleanField()))
400 409  
401 410 @classmethod
402 411 def cards_hidden_by(cls, user):
flashy/settings.py View file @ 90df9a5
... ... @@ -36,7 +36,6 @@
36 36 'django.contrib.messages',
37 37 'django.contrib.staticfiles',
38 38 'ws4redis',
39   -
40 39 'rest_framework_swagger',
41 40 'rest_framework',
42 41 'django_extensions',
... ... @@ -119,6 +118,9 @@
119 118 SERVER_EMAIL = 'noreply@flashy.cards'
120 119  
121 120 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
  121 +
  122 +if DEBUG:
  123 + INSTALLED_APPS.append('debug_toolbar')
122 124  
123 125 if IN_PRODUCTION:
124 126 INSTALLED_APPS.append('django_ses')
requirements.txt View file @ 90df9a5
... ... @@ -15,4 +15,5 @@
15 15 django-extensions
16 16 django-redis-sessions
17 17 python-gcm
  18 +django-debug-toolbar