diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-12-01 11:53:08 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-12-01 16:00:37 +0100 |
commit | 0bd5582a75d5a610885241ba52186033e2272424 (patch) | |
tree | a1af1842d9ddce37f1a9ec2815e0d289fbb405f4 | |
parent | 85b8ca13fc2e164971f7cbb06c4a0c5b0a1a0770 (diff) | |
download | hyperkitty-0bd5582a75d5a610885241ba52186033e2272424.tar.gz hyperkitty-0bd5582a75d5a610885241ba52186033e2272424.tar.xz hyperkitty-0bd5582a75d5a610885241ba52186033e2272424.zip |
Better handling of the user votes cache
-rw-r--r-- | hyperkitty/lib/mailman.py | 9 | ||||
-rw-r--r-- | hyperkitty/tests/test_views.py | 6 | ||||
-rw-r--r-- | hyperkitty/views/message.py | 6 |
3 files changed, 11 insertions, 10 deletions
diff --git a/hyperkitty/lib/mailman.py b/hyperkitty/lib/mailman.py index 0e940ee..45f4289 100644 --- a/hyperkitty/lib/mailman.py +++ b/hyperkitty/lib/mailman.py @@ -61,16 +61,17 @@ def get_subscriptions(store, client, mm_user): # de-duplicate subscriptions if mlist in [ s["list_name"] for s in subscriptions ]: continue + posts_count = store.get_message_count_by_user_id( + mm_user.user_id, mlist) cache_key = "user:%s:list:%s:votes" % (mm_user.user_id, mlist) - likes, dislikes, posts_count = cache.get(cache_key, (None, None, None)) + likes, dislikes = cache.get(cache_key, (None, None)) if likes is None or dislikes is None or posts_count is None: email_hashes = store.get_message_hashes_by_user_id( mm_user.user_id, mlist) likes, dislikes, _myvote = get_votes(mlist, email_hashes) - posts_count = len(email_hashes) - cache.set(cache_key, (likes, dislikes, posts_count)) + cache.set(cache_key, (likes, dislikes)) all_posts_url = "%s?list=%s" % \ - (reverse("user_posts", mm_user.user_id), mlist) + (reverse("user_posts", args=[mm_user.user_id]), mlist) likestatus = "neutral" if likes - dislikes >= 10: likestatus = "likealot" diff --git a/hyperkitty/tests/test_views.py b/hyperkitty/tests/test_views.py index 6c1ac83..2ff2754 100644 --- a/hyperkitty/tests/test_views.py +++ b/hyperkitty/tests/test_views.py @@ -179,14 +179,12 @@ class MessageViewsTestCase(TestCase): self.user = User.objects.create_user( 'testuser', 'test@example.com', 'testPass') # Fake KittStore - class FakeThread(object): - thread_id = None class FakeMessage(object): def __init__(self, h): self.message_id_hash = h self.list_name = "list@example.com" - self.thread = FakeThread() - self.thread.thread_id = h + self.thread_id = h + self.user_id = None self.store = Mock() self.store.get_message_by_hash_from_list.side_effect = \ lambda l, h: FakeMessage(h) diff --git a/hyperkitty/views/message.py b/hyperkitty/views/message.py index 2ed53e4..a01424e 100644 --- a/hyperkitty/views/message.py +++ b/hyperkitty/views/message.py @@ -132,9 +132,11 @@ def vote(request, mlist_fqdn, message_id_hash): v.vote = value v.save() - # Invalidate the cache for the thread votes + # Invalidate the cache for the thread and user votes cache.delete("list:%s:thread:%s:votes" - % (mlist_fqdn, message.thread.thread_id)) + % (mlist_fqdn, message.thread_id)) + if message.user_id: + cache.delete("user:%s:list:%s:votes" % (user_id, mlist_fqdn)) # Extract all the votes for this message to refresh it set_message_votes(message, request.user) |