summaryrefslogtreecommitdiff
path: root/todolists/utils.py
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-04-27 08:59:00 -0500
committerDan McGee <dan@archlinux.org>2012-04-27 09:12:26 -0500
commitdc94eade03022ce3a5286f5e781576321a5f1653 (patch)
tree604b10eaba12f066fa6a843a4f5342a89eb11fb5 /todolists/utils.py
parent3f150dcfade9443b3435309cb928f330966eb749 (diff)
Incomplete-only todolists optimization
We can push this down to the database if we know in advance we only need the incomplete lists. This helps our call on the developer dashboard quite a bit; the time of the single query in question drops from >1300ms to around 40ms. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'todolists/utils.py')
-rw-r--r--todolists/utils.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/todolists/utils.py b/todolists/utils.py
index 24101e86..94f39f71 100644
--- a/todolists/utils.py
+++ b/todolists/utils.py
@@ -3,7 +3,7 @@ from django.db.models import Count
from main.models import Todolist
-def get_annotated_todolists():
+def get_annotated_todolists(incomplete_only=False):
qs = Todolist.objects.all()
lists = qs.select_related('creator').defer(
'creator__email', 'creator__password', 'creator__is_staff',
@@ -13,8 +13,12 @@ def get_annotated_todolists():
incomplete = qs.filter(todolistpkg__complete=False).annotate(
Count('todolistpkg')).values_list('id', 'todolistpkg__count')
- # tag each list with an incomplete package count
lookup = dict(incomplete)
+
+ if incomplete_only:
+ lists = lists.filter(id__in=lookup.keys())
+
+ # tag each list with an incomplete package count
for todolist in lists:
todolist.incomplete_count = lookup.get(todolist.id, 0)