Store list of which months have messages, use this to build index pages
authorMagnus Hagander <magnus@hagander.net>
Sun, 17 Jun 2012 13:58:39 +0000 (21:58 +0800)
committerMagnus Hagander <magnus@hagander.net>
Sun, 17 Jun 2012 13:58:39 +0000 (21:58 +0800)
django/archives/mailarchives/templates/monthlist.html [new file with mode: 0644]
django/archives/mailarchives/views.py
django/archives/urls.py
loader/load_message.py
loader/materialize_all_months.sql [new file with mode: 0644]
loader/schema.sql

diff --git a/django/archives/mailarchives/templates/monthlist.html b/django/archives/mailarchives/templates/monthlist.html
new file mode 100644 (file)
index 0000000..e069849
--- /dev/null
@@ -0,0 +1,18 @@
+{%extends "base.html"%}
+{%block title%}PostgreSQL Mailing Lists: {{list.listname}}{%endblock%}
+{%load pgfilters%}
+{%block layoutblock%}
+<h1>{{list.listname}}</h1>
+{%regroup months by year as yearmonth %}
+<ul>
+{%for year in yearmonth%}
+ <li>{{year.grouper}}
+  <ul>
+   {%for month in year.list%}
+    <li><a href="/{{list.listname}}/{{month.year}}-{{month.month|stringformat:"02d"}}/">{{month.date|date:"F"}}</a></li>
+   {%endfor%}
+  </ul>
+ </li>
+{%endfor%}
+</ul>
+{%endblock%}
index 382b651e68efbd158fdaadb928c038d1a219f017..c1aaf6ebe4cbae056e24c41a201f214518a4c874 100644 (file)
@@ -8,6 +8,17 @@ from datetime import datetime
 
 from models import *
 
+def monthlist(request, listname):
+       l = get_object_or_404(List, listname=listname)
+       curs = connection.cursor()
+       curs.execute("SELECT year, month FROM list_months WHERE listid=%(listid)s ORDER BY year DESC, month DESC", {'listid': l.listid})
+       months=[{'year':r[0],'month':r[1], 'date':datetime(r[0],r[1],1) }for r in curs.fetchall()]
+
+       return render_to_response('monthlist.html', {
+                       'list': l,
+                       'months': months,
+                       })
+
 def render_datelist_from(request, l, d, title):
        mlist = Message.objects.select_related().filter(date__gte=d).extra(where=["threadid IN (SELECT threadid FROM list_threads WHERE listid=%s)" % l.listid]).order_by('date')[:200]
        return render_to_response('datelist.html', {
index 93633bcd6735d49ca1b16fedc294ff0de8d8ee3d..4bb8ef4004e7baf1271ca22dd2f5b7b84a5ddb92 100644 (file)
@@ -19,6 +19,7 @@ urlpatterns = patterns('',
     (r'^test/oldsite/([^/]+)/$', 'archives.mailarchives.views.oldsite'),
 
     (r'^message-id/([^/]+)/', 'archives.mailarchives.views.message'),
+    (r'^([\w-]+)/$', 'archives.mailarchives.views.monthlist'),
     (r'^([\w-]+)/(\d+)-(\d+)/$', 'archives.mailarchives.views.datelist'),
     (r'^([\w-]+)/since/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})', 'archives.mailarchives.views.datelistsincetime'),
     (r'^([\w-]+)/since/([^/]+)/$', 'archives.mailarchives.views.datelistsince'),
index 10a7413928365f50350fb0c543d5258914bea1f4..25c81c06e8fdb6aba6d20fe499f814b8c6d556fe 100755 (executable)
@@ -61,6 +61,16 @@ class ArchivesParser(object):
 
        def store(self, conn, listid):
                curs = conn.cursor()
+
+               # Potentially add the information that there exists a mail for
+               # this month. We do that this early since we're always going to
+               # make the check anyway, and this keeps the code in one place..
+               curs.execute("INSERT INTO list_months (listid, year, month) SELECT %(listid)s, %(year)s, %(month)s WHERE NOT EXISTS (SELECT listid FROM list_months WHERE listid=%(listid)s AND year=%(year)s AND month=%(month)s)", {
+                                               'listid': listid,
+                                               'year': self.date.year,
+                                               'month': self.date.month,
+                                               })
+
                curs.execute("SELECT threadid, EXISTS(SELECT threadid FROM list_threads lt WHERE lt.listid=%(listid)s AND lt.threadid=m.threadid) FROM messages m WHERE m.messageid=%(messageid)s", {
                                'messageid': self.msgid,
                                'listid': listid,
diff --git a/loader/materialize_all_months.sql b/loader/materialize_all_months.sql
new file mode 100644 (file)
index 0000000..658c16f
--- /dev/null
@@ -0,0 +1,10 @@
+\set ON_ERROR_STOP
+BEGIN;
+
+TRUNCATE TABLE list_months;
+
+INSERT INTO list_months(listid, year, month)
+SELECT DISTINCT listid, EXTRACT(year FROM date), EXTRACT(month FROM date)
+FROM messages INNER JOIN list_threads ON messages.threadid=list_threads.threadid;
+
+COMMIT;
index c8189a8e9fd67da52d254f1e3a827a5b8cd36bfa..39d487d73432ca6be12cb7fe3fa84c652857828c 100644 (file)
@@ -28,7 +28,14 @@ CREATE UNIQUE INDEX idx_unresolved_msgid_message ON unresolved_messages(msgid, m
 
 CREATE TABLE lists(
    listid int NOT NULL PRIMARY KEY,
-   listname text NOT NULL
+   listname text NOT NULL,
+);
+
+CREATE TABLE list_months(
+   listid int NOT NULL,
+   year int NOT NULL,
+   month int NOT NULL,
+   CONSTRAINT list_months_pk PRIMARY KEY (listid, year, month)
 );
 
 CREATE TABLE list_threads(