Add API support for getting "latest messages" across lists
authorMagnus Hagander <magnus@hagander.net>
Sun, 2 Sep 2018 11:57:52 +0000 (13:57 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sun, 2 Sep 2018 11:57:52 +0000 (13:57 +0200)
Previously, a specific list had to be chosen, but there's use for being
able to look at the global view as well. Since the requests are
restricted to registered API clients anyway, it shouldn't be a load
issue.

django/archives/mailarchives/api.py
django/archives/urls.py

index ca0b736a28e604cf47d808a8f171388654a95bd0..6ba137880a639a2fe49503f59d51ed8d90a86e4e 100644 (file)
@@ -60,8 +60,13 @@ def latest(request, listname):
                extrawhere.append("fti @@ plainto_tsquery('public.pg', %s)")
                extraparams.append(request.GET['s'])
 
-       list = get_object_or_404(List, listname=listname)
-       extrawhere.append("threadid IN (SELECT threadid FROM list_threads WHERE listid=%s)" % list.listid)
+       if listname != '*':
+               list = get_object_or_404(List, listname=listname)
+               extrawhere.append("threadid IN (SELECT threadid FROM list_threads WHERE listid=%s)" % list.listid)
+       else:
+               list = None
+               extrawhere=''
+
        mlist = Message.objects.defer('bodytxt', 'cc', 'to').select_related().extra(where=extrawhere, params=extraparams).order_by('-date')[:limit]
        allyearmonths = set([(m.date.year, m.date.month) for m in mlist])
 
@@ -75,7 +80,9 @@ def latest(request, listname):
 
        # Make sure this expires from the varnish cache when new entries show
        # up in this month.
-       resp['X-pglm'] = ':%s:' % (':'.join(['%s/%s/%s' % (list.listid, year, month) for year, month in allyearmonths]))
+       # XXX: need to deal with the global view, but for now API callers come in directly
+       if list:
+               resp['X-pglm'] = ':%s:' % (':'.join(['%s/%s/%s' % (list.listid, year, month) for year, month in allyearmonths]))
        return resp
 
 
index cc80874403365f81fdb25c9c5d6ad23cb9778790..fd26056d41addbd96bd942889706921da50db2e4 100644 (file)
@@ -51,7 +51,7 @@ urlpatterns = [
     url(r'^message-id/attachment/(\d+)/.*$', archives.mailarchives.views.attachment),
 
     # API calls
-    url(r'^list/([\w-]+)/latest.json$', archives.mailarchives.api.latest),
+    url(r'^list/([\w-]+|\*)/latest.json$', archives.mailarchives.api.latest),
     url(r'^message-id.json/(.+)$', archives.mailarchives.api.thread),
     url(r'^listinfo/$', archives.mailarchives.api.listinfo),
 #    url(r'^thread/(.+)/subscribe/$', archives.mailarchives.api.thread_subscribe),