Mercurial > public > sg101
comparison gpp/forums/models.py @ 387:b15726767ab8
Fixing #191; terrible performance on the combined forums RSS feed query. Use an .extra() clause to force the WHERE on a query to use the primary key.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 19 Mar 2011 01:52:41 +0000 |
parents | 9fcd366f22dc |
children | 9af6bd45c1f8 |
comparison
equal
deleted
inserted
replaced
386:9fcd366f22dc | 387:b15726767ab8 |
---|---|
4 import datetime | 4 import datetime |
5 | 5 |
6 from django.db import models | 6 from django.db import models |
7 from django.db.models import Q | 7 from django.db.models import Q |
8 from django.contrib.auth.models import User, Group | 8 from django.contrib.auth.models import User, Group |
9 from django.core.cache import cache | |
9 | 10 |
10 from core.markup import site_markup | 11 from core.markup import site_markup |
11 from oembed.models import Oembed | 12 from oembed.models import Oembed |
12 | 13 |
13 | 14 |
68 return qs.values_list('id', flat=True) | 69 return qs.values_list('id', flat=True) |
69 | 70 |
70 def public_forums(self): | 71 def public_forums(self): |
71 """Returns a queryset containing the public forums.""" | 72 """Returns a queryset containing the public forums.""" |
72 return self.filter(category__groups__isnull=True) | 73 return self.filter(category__groups__isnull=True) |
74 | |
75 def public_forum_ids(self): | |
76 """ | |
77 Returns a list of ids for the public forums; the list is cached for | |
78 performance. | |
79 """ | |
80 public_forums = cache.get('public_forum_ids') | |
81 if public_forums is None: | |
82 public_forums = list(self.filter( | |
83 category__groups__isnull=True).values_list('id', flat=True)) | |
84 cache.set('public_forum_ids', public_forums, 3600) | |
85 return public_forums | |
73 | 86 |
74 def _for_user(self, user): | 87 def _for_user(self, user): |
75 """Common code for the xxx_for_user() methods.""" | 88 """Common code for the xxx_for_user() methods.""" |
76 if user.is_superuser: | 89 if user.is_superuser: |
77 qs = self.all() | 90 qs = self.all() |