summaryrefslogtreecommitdiffstats
path: root/hyperkitty/lib/voting.py
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2013-11-15 16:03:52 +0100
committerAurélien Bompard <aurelien@bompard.org>2013-11-20 19:15:41 +0100
commit64e477ba7b4845f768ba60e5a9f8fb580a3dd44e (patch)
tree9f1943efc84b634e09f24e1d79c0f84ccde89b69 /hyperkitty/lib/voting.py
parent5c0e4e11dad001952f7fe745b22e1cf63fbc50fd (diff)
downloadhyperkitty-64e477ba7b4845f768ba60e5a9f8fb580a3dd44e.tar.gz
hyperkitty-64e477ba7b4845f768ba60e5a9f8fb580a3dd44e.tar.xz
hyperkitty-64e477ba7b4845f768ba60e5a9f8fb580a3dd44e.zip
Cache the votes for threads
Diffstat (limited to 'hyperkitty/lib/voting.py')
-rw-r--r--hyperkitty/lib/voting.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/hyperkitty/lib/voting.py b/hyperkitty/lib/voting.py
index d21d977..56fee7e 100644
--- a/hyperkitty/lib/voting.py
+++ b/hyperkitty/lib/voting.py
@@ -20,6 +20,7 @@
#
+from django.core.cache import cache
from hyperkitty.models import Rating
@@ -59,9 +60,16 @@ def set_message_votes(message, user=None):
def set_thread_votes(thread, user=None):
- total = 0
- # XXX: 1 SQL request per thread, possible optimization here
- likes, dislikes, myvote = get_votes(thread.email_id_hashes)
+ total = myvote = 0
+ likes = dislikes = None
+ cache_key = "list:%s:thread:%s:votes" % (thread.list_name, thread.thread_id)
+ if user is None or not user.is_authenticated():
+ likes, dislikes = cache.get(cache_key, (None, None))
+ myvote = 0
+ if likes is None or dislikes is None:
+ # XXX: 1 SQL request per thread, possible optimization here
+ likes, dislikes, myvote = get_votes(thread.email_id_hashes)
+ cache.set(cache_key, (likes, dislikes))
total = likes + dislikes
try:
thread.likes = likes / total