Commit ee6a0605e6b96540872619e5dd636b2e642f366c

Authored by Luan
2 parents 976c93ab b8efb2cc

Merge branch 'master' of github.com:TracyWebTech/colab

src/accounts/views.py
... ... @@ -23,6 +23,7 @@ from haystack.query import SearchQuerySet
23 23 from super_archives.models import EmailAddress, Message
24 24 from super_archives.utils.email import send_email_lists
25 25 from search.utils import trans
  26 +from proxy.models import WikiCollabCount, TicketCollabCount
26 27 from .forms import (UserCreationForm, ListsForm, UserUpdateForm,
27 28 ChangeXMPPPasswordForm)
28 29 from .errors import XMPPChangePwdException
... ... @@ -65,11 +66,25 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView):
65 66 {'fullname_and_username__contains': user.username},
66 67 )
67 68  
  69 + counter_class = {
  70 + 'wiki': WikiCollabCount,
  71 + 'ticket': TicketCollabCount,
  72 + }
  73 +
68 74 for type in ['thread', 'ticket', 'wiki', 'changeset', 'attachment']:
69   - sqs = SearchQuerySet()
70   - for filter_or in fields_or_lookup:
71   - sqs = sqs.filter_or(type=type, **filter_or)
72   - count_types[trans(type)] = sqs.count()
  75 + CounterClass = counter_class.get(type)
  76 + if CounterClass:
  77 + try:
  78 + counter = CounterClass.objects.get(username=user.username)
  79 + except CounterClass.DoesNotExist:
  80 + count_types[trans(type)] = 0
  81 + else:
  82 + count_types[trans(type)] = counter.count
  83 + else:
  84 + sqs = SearchQuerySet()
  85 + for filter_or in fields_or_lookup:
  86 + sqs = sqs.filter_or(type=type, **filter_or)
  87 + count_types[trans(type)] = sqs.count()
73 88  
74 89 context['type_count'] = count_types
75 90  
... ...
src/badger/utils.py
... ... @@ -2,16 +2,14 @@
2 2  
3 3 from django.db.models import Count
4 4  
5   -from proxy.models import Revision, Ticket, Wiki
  5 +from proxy.models import (Revision, Ticket, Wiki,
  6 + WikiCollabCount, TicketCollabCount)
6 7 from accounts.models import User
7 8  
8 9  
9 10 def get_wiki_counters():
10   - return {
11   - author: count for author, count in Wiki.objects.values_list(
12   - 'author'
13   - ).annotate(count=Count('author'))
14   - }
  11 + return {author: count for author, count in
  12 + WikiCollabCount.objects.values_list()}
15 13  
16 14  
17 15 def get_revision_counters():
... ... @@ -23,11 +21,8 @@ def get_revision_counters():
23 21  
24 22  
25 23 def get_ticket_counters():
26   - return {
27   - author: count for author, count in Ticket.objects.values_list(
28   - 'author'
29   - ).annotate(count=Count('author'))
30   - }
  24 + return {author: count for author, count in
  25 + TicketCollabCount.objects.values_list()}
31 26  
32 27  
33 28 def get_users_counters():
... ...
src/proxy/models.py
... ... @@ -130,3 +130,21 @@ class Wiki(models.Model, HitCounterModelMixin):
130 130 return User.objects.get(username=self.modified_by)
131 131 except User.DoesNotExist:
132 132 return None
  133 +
  134 +
  135 +class WikiCollabCount(models.Model):
  136 + author = models.TextField(primary_key=True)
  137 + count = models.IntegerField()
  138 +
  139 + class Meta:
  140 + managed = False
  141 + db_table = 'wiki_collab_count_view'
  142 +
  143 +
  144 +class TicketCollabCount(models.Model):
  145 + author = models.TextField(primary_key=True)
  146 + count = models.IntegerField()
  147 +
  148 + class Meta:
  149 + managed = False
  150 + db_table = 'ticket_collab_count_view'
... ...