Commit ad2611858466bf0f7e8b58a93fb04bbe753aecda
1 parent
6c7f0db8
Exists in
master
and in
39 other branches
minor changes and caching home chart - closes #84
Showing
1 changed file
with
18 additions
and
5 deletions
Show diff stats
src/home/views.py
1 | 1 | |
2 | 2 | from collections import OrderedDict |
3 | 3 | |
4 | +from django.core.cache import cache | |
4 | 5 | from django.shortcuts import render |
5 | 6 | |
6 | 7 | from search.utils import trans |
7 | 8 | from haystack.query import SearchQuerySet |
8 | 9 | |
10 | +from proxy.models import WikiCollabCount, TicketCollabCount | |
9 | 11 | from super_archives.models import Thread |
10 | 12 | |
11 | 13 | |
... | ... | @@ -16,11 +18,22 @@ def index(request): |
16 | 18 | latest_threads = Thread.objects.all()[:6] |
17 | 19 | hottest_threads = Thread.highest_score.from_haystack()[:6] |
18 | 20 | |
19 | - count_types = OrderedDict() | |
20 | - for type in ['thread', 'ticket', 'wiki', 'changeset', 'attachment']: | |
21 | - count_types[trans(type)] = SearchQuerySet().filter( | |
22 | - type=type, | |
23 | - ).count() | |
21 | + count_types = cache.get('home_chart') | |
22 | + if count_types is None: | |
23 | + count_types = OrderedDict() | |
24 | + for type in ['thread', 'changeset', 'attachment']: | |
25 | + count_types[trans(type)] = SearchQuerySet().filter( | |
26 | + type=type, | |
27 | + ).count() | |
28 | + | |
29 | + count_types[trans('ticket')] = sum([ | |
30 | + ticket.count for ticket in TicketCollabCount.objects.all() | |
31 | + ]) | |
32 | + | |
33 | + count_types[trans('wiki')] = sum([ | |
34 | + wiki.count for wiki in WikiCollabCount.objects.all() | |
35 | + ]) | |
36 | + cache.set('home_chart', count_types, 60) | |
24 | 37 | |
25 | 38 | context = { |
26 | 39 | 'hottest_threads': hottest_threads[:6], | ... | ... |