Commit d323564f0cb891b2285e7dda8e19ea1ce0cabe8d
Exists in
master
and in
39 other branches
Merge branch 'master' of github.com:TracyWebTech/colab
Showing
3 changed files
with
14 additions
and
8 deletions
Show diff stats
src/hitcount/models.py
... | ... | @@ -45,7 +45,11 @@ class HitCountModelMixin(object): |
45 | 45 | cache.set(cache_key, True) |
46 | 46 | |
47 | 47 | # Everything ok, so just increment the page count |
48 | - hit_ = Hit.objects.get_or_create(content_type=content_type, | |
49 | - object_pk=self.pk)[0] | |
50 | - hit_.hits += 1 | |
51 | - hit_.save() | |
48 | + hit_pk = Hit.objects.get_or_create(content_type=content_type, | |
49 | + object_pk=self.pk)[0].pk | |
50 | + | |
51 | + # Using this way instead of hits += 1 forces django to | |
52 | + # call the UPDATE directly in the database avoiding | |
53 | + # cuncurrency problems | |
54 | + Hit.objects.filter(pk=hit_pk).update(hits=models.F("hits") + 1) | |
55 | + | ... | ... |
src/hitcount/views.py
1 | 1 | from django.shortcuts import render |
2 | 2 | |
3 | 3 | class HitCountViewMixin(object): |
4 | - def get_object(self): | |
5 | - raise NotImplementedError | |
4 | + def get_object(self, *args, **kwargs): | |
5 | + try: | |
6 | + super(HitCountViewMixin, self).get_object(*args, **kwargs) | |
7 | + except AttributeError: | |
8 | + raise NotImplementedError | |
6 | 9 | |
7 | 10 | def dispatch(self, request, *args, **kwargs): |
8 | 11 | response = super(HitCountViewMixin, self).dispatch(request, | ... | ... |
src/super_archives/views.py
... | ... | @@ -30,8 +30,7 @@ def thread(request, mailinglist, thread_token): |
30 | 30 | |
31 | 31 | thread = Thread.objects.get(subject_token=thread_token, |
32 | 32 | mailinglist__name=mailinglist) |
33 | - | |
34 | - thread.hit() | |
33 | + thread.hit(request) | |
35 | 34 | |
36 | 35 | order_by = request.GET.get('order') |
37 | 36 | if order_by == 'voted': | ... | ... |