From ec7da1aac20a01838d30e02d550c13b22414be73 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Thu, 30 Aug 2012 17:58:36 +0200 Subject: Adapt to the new Storm-based KittyStore --- hyperkitty/api.py | 9 +++--- hyperkitty/lib/__init__.py | 22 ++++++++++++- hyperkitty/models.py | 7 ++-- hyperkitty/templates/messages/message.html | 4 +-- hyperkitty/templates/month_view.html | 6 ++-- hyperkitty/templates/search.html | 6 ++-- hyperkitty/urls.py | 4 +-- hyperkitty/views/list.py | 51 ++++++++++++++++-------------- hyperkitty/views/message.py | 23 +++++++------- hyperkitty/views/pages.py | 6 +++- hyperkitty/views/thread.py | 13 ++++---- 11 files changed, 88 insertions(+), 63 deletions(-) (limited to 'hyperkitty') diff --git a/hyperkitty/api.py b/hyperkitty/api.py index c39646e..1cea89c 100644 --- a/hyperkitty/api.py +++ b/hyperkitty/api.py @@ -8,9 +8,7 @@ import json import re from hyperkitty.utils import log - -import kittystore -STORE = kittystore.get_store(settings.KITTYSTORE_URL) +from hyperkitty.lib import ThreadSafeStorePool class EmailResource(View): @@ -20,6 +18,7 @@ class EmailResource(View): def get(self, request, mlist_fqdn, messageid): list_name = mlist_fqdn.split('@')[0] + STORE = ThreadSafeStorePool().get() email = STORE.get_message_by_hash_from_list(list_name, messageid) if not email: return HttpResponse(status=404) @@ -34,6 +33,7 @@ class ThreadResource(View): def get(self, request, mlist_fqdn, threadid): list_name = mlist_fqdn.split('@')[0] + STORE = ThreadSafeStorePool().get() thread = STORE.get_thread(list_name, threadid) if not thread: return HttpResponse(status=404) @@ -61,7 +61,8 @@ class SearchResource(View): query_string = {field.capitalize(): re.compile(regex, re.IGNORECASE)} - print query_string, field, keyword + #print query_string, field, keyword + STORE = ThreadSafeStorePool().get() threads = STORE.search_archives(list_name, query_string) if not threads: return HttpResponse(status=404) diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py index aa5a3d9..d6ad4aa 100644 --- a/hyperkitty/lib/__init__.py +++ b/hyperkitty/lib/__init__.py @@ -1,7 +1,27 @@ #-*- coding: utf-8 -*- -from hashlib import md5 import urllib +from hashlib import md5 +import threading + +from django.conf import settings + +from hyperkitty.utils import log + +import kittystore + + +class ThreadSafeStorePool(object): + + def __init__(self): + self._local = threading.local() + + def get(self): + try: + return self._local.store + except AttributeError: + self._local.store = kittystore.get_store(settings.KITTYSTORE_URL, debug=False) + return self._local.store def gravatar_url(email): diff --git a/hyperkitty/models.py b/hyperkitty/models.py index 9389a05..00c5128 100644 --- a/hyperkitty/models.py +++ b/hyperkitty/models.py @@ -25,9 +25,7 @@ from django.conf import settings from hyperkitty.utils import log - -import kittystore -STORE = kittystore.get_store(settings.KITTYSTORE_URL) +from hyperkitty.lib import ThreadSafeStorePool class Rating(models.Model): @@ -65,7 +63,8 @@ class UserProfile(models.Model): for vote in votes: list_name = vote.list_address.split('@')[0] - message = STORE.get_message_by_id_from_list(list_name, vote.messageid) + STORE = ThreadSafeStorePool().get() + message = STORE.get_message_by_id_from_list(vote.list_address, vote.messageid) vote.message = message return votes diff --git a/hyperkitty/templates/messages/message.html b/hyperkitty/templates/messages/message.html index 67d5653..c32805e 100644 --- a/hyperkitty/templates/messages/message.html +++ b/hyperkitty/templates/messages/message.html @@ -3,7 +3,7 @@
{% gravatar_img_for_email email.email 40 %} @@ -20,7 +20,7 @@ {{email.content}}
-