Commit 920829965b4f8aad8271febafd1d6a2a155d8b9e
1 parent
55eab2f1
Exists in
master
and in
39 other branches
Incrementing hits directly in DB
Showing
2 changed files
with
9 additions
and
6 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/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': | ... | ... |