summaryrefslogtreecommitdiffstats
path: root/hyperkitty
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-11-25 22:48:05 +0100
committerAurélien Bompard <aurelien@bompard.org>2012-11-25 22:48:05 +0100
commit881cf629918fcd2bafcf69878688972f64bc1dff (patch)
treea72376fbe372791c310466487435354c8ee82ea4 /hyperkitty
parent7557ae816460130f81d499352b83012707f752e4 (diff)
downloadhyperkitty-881cf629918fcd2bafcf69878688972f64bc1dff.tar.gz
hyperkitty-881cf629918fcd2bafcf69878688972f64bc1dff.tar.xz
hyperkitty-881cf629918fcd2bafcf69878688972f64bc1dff.zip
Get rid of redundant SQL queries
Diffstat (limited to 'hyperkitty')
-rw-r--r--hyperkitty/templates/recent_activities.html8
-rw-r--r--hyperkitty/views/list.py17
2 files changed, 17 insertions, 8 deletions
diff --git a/hyperkitty/templates/recent_activities.html b/hyperkitty/templates/recent_activities.html
index cca93d8..242d38a 100644
--- a/hyperkitty/templates/recent_activities.html
+++ b/hyperkitty/templates/recent_activities.html
@@ -82,7 +82,7 @@
<span class="thread_id">#{{forloop.counter}}</span>
<span class="thread_title"><a name="{{thread.thread_id}}"
href="{% url thread threadid=thread.thread_id, mlist_fqdn=list_address %}"
- >{{ thread.starting_email.subject|strip_subject:mlist }}</a></span>
+ >{{ thread.subject|strip_subject:mlist }}</a></span>
<div class="thread_stats">
<ul class="inline-block">
{% if thread.category_tag %}
@@ -106,7 +106,7 @@
{{ thread.participants|length }}
</li>
<li class="discussion">
- {{ thread|length }}
+ {{ thread.length }}
</li>
</ul>
</div>
@@ -123,7 +123,7 @@
<span class="thread_id">#{{forloop.counter}}</span>
<span class="thread_title"> <a name="{{thread.thread_id}}"
href="{% url thread threadid=thread.thread_id, mlist_fqdn=list_address %}"
- >{{ thread.starting_email.subject|strip_subject:mlist }}</a> </span>
+ >{{ thread.subject|strip_subject:mlist }}</a> </span>
<div class="thread_stats">
<ul class="inline-block">
{% if thread.category_tag %}
@@ -147,7 +147,7 @@
{{ thread.participants|length }}
</li>
<li class="discussion">
- {{ thread|length }}
+ {{ thread.length }}
</li>
</ul>
</div>
diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py
index 3b51152..f44379a 100644
--- a/hyperkitty/views/list.py
+++ b/hyperkitty/views/list.py
@@ -25,6 +25,7 @@ import logging
from calendar import timegm
from datetime import datetime, timedelta
from urlparse import urljoin
+from collections import namedtuple
import django.utils.simplejson as simplejson
from django.http import HttpResponse, HttpResponseRedirect
@@ -196,12 +197,20 @@ def list(request, mlist_fqdn=None):
store = get_store(request)
mlist = store.get_list(mlist_fqdn)
- threads = store.get_threads(list_name=mlist_fqdn, start=begin_date,
+ threads_result = store.get_threads(list_name=mlist_fqdn, start=begin_date,
end=end_date)
+ threads = []
+ Thread = namedtuple('Thread', ["thread_id", "subject", "participants",
+ "length", "date_active"])
participants = set()
dates = {}
- for thread in threads:
+ for thread_obj in threads_result:
+ thread = Thread(thread_obj.thread_id, thread_obj.subject,
+ thread_obj.participants, len(thread_obj),
+ thread_obj.date_active)
+ threads.append(thread)
+
month = thread.date_active.month
if month < 10:
month = '0%s' % month
@@ -217,10 +226,10 @@ def list(request, mlist_fqdn=None):
participants.update(thread.participants)
# top threads are the one with the most answers
- top_threads = sorted(threads, key=lambda entry: len(entry), reverse=True)
+ top_threads = sorted(threads, key=lambda t: t.length, reverse=True)
# active threads are the ones that have the most recent posting
- active_threads = sorted(threads, key=lambda entry: entry.date_active, reverse=True)
+ active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True)
archives_length = get_months(store, mlist_fqdn)