summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2018-02-21 17:31:54 +0000
committerMagnus Hagander2018-02-21 17:45:19 +0000
commitb8274b5875a4742800307ed645f1137c10e2a09d (patch)
treefd91a0b4b27e7f822c8bedfcf976c5662b152621
parentda4c56069c8f61dd7e8f499827618e527e1a4a1b (diff)
Implement thread notification receiving
This allows the archivs server to ping the CF app to pick up updates to mailthreads quicker.
-rw-r--r--pgcommitfest/commitfest/ajax.py16
-rw-r--r--pgcommitfest/commitfest/util.py1
-rw-r--r--pgcommitfest/commitfest/views.py24
-rw-r--r--pgcommitfest/settings.py1
-rw-r--r--pgcommitfest/urls.py1
-rwxr-xr-xtools/commitfest/update_archive_threads.py19
6 files changed, 44 insertions, 18 deletions
diff --git a/pgcommitfest/commitfest/ajax.py b/pgcommitfest/commitfest/ajax.py
index cffc33d..b65de8d 100644
--- a/pgcommitfest/commitfest/ajax.py
+++ b/pgcommitfest/commitfest/ajax.py
@@ -79,6 +79,22 @@ def getMessages(request):
r = _archivesAPI('/message-id.json/%s' % thread.messageid)
return sorted(r, key=lambda x: x['date'], reverse=True)
+def refresh_single_thread(thread):
+ r = sorted(_archivesAPI('/message-id.json/%s' % thread.messageid), key=lambda x: x['date'])
+ if thread.latestmsgid != r[-1]['msgid']:
+ # There is now a newer mail in the thread!
+ thread.latestmsgid = r[-1]['msgid']
+ thread.latestmessage = r[-1]['date']
+ thread.latestauthor = r[-1]['from']
+ thread.latestsubject = r[-1]['subj']
+ thread.save()
+ parse_and_add_attachments(r, thread)
+ # Potentially update the last mail date - if there wasn't already a mail on each patch
+ # from a *different* thread that had an earlier date.
+ for p in thread.patches.filter(lastmail__lt=thread.latestmessage):
+ p.lastmail = thread.latestmessage
+ p.save()
+
@transaction.atomic
def annotateMessage(request):
thread = get_object_or_404(MailThread, pk=int(request.POST['t']))
diff --git a/pgcommitfest/commitfest/util.py b/pgcommitfest/commitfest/util.py
index 7a38c7b..84f543d 100644
--- a/pgcommitfest/commitfest/util.py
+++ b/pgcommitfest/commitfest/util.py
@@ -41,3 +41,4 @@ class DiffableModel(object):
fields = [field.name for field in self._meta.fields]
fields.extend([field.name for field in self._meta.many_to_many])
return model_to_dict(self, fields=fields)
+
diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py
index 8eadafa..68bdbef 100644
--- a/pgcommitfest/commitfest/views.py
+++ b/pgcommitfest/commitfest/views.py
@@ -14,14 +14,16 @@ from django.conf import settings
from datetime import datetime
from email.mime.text import MIMEText
from email.utils import formatdate, make_msgid
+import json
from pgcommitfest.mailqueue.util import send_mail, send_simple_mail
from pgcommitfest.userprofile.util import UserWrapper
from models import CommitFest, Patch, PatchOnCommitFest, PatchHistory, Committer
+from models import MailThread
from forms import PatchForm, NewPatchForm, CommentForm, CommitFestFilterForm
from forms import BulkEmailForm
-from ajax import doAttachThread
+from ajax import doAttachThread, refresh_single_thread
from feeds import ActivityFeed
def home(request):
@@ -662,3 +664,23 @@ def send_email(request, cfid):
'breadcrumbs': [{'title': cf.title, 'href': '/%s/' % cf.pk},],
'savebutton': 'Send email',
})
+
+
+@csrf_exempt
+def thread_notify(request):
+ if request.method != 'POST':
+ return HttpResponseForbidden("Invalid method")
+
+ j = json.loads(request.body)
+ if j['apikey'] != settings.ARCHIVES_APIKEY:
+ return HttpResponseForbidden("Invalid API key")
+
+ for m in j['messageids']:
+ try:
+ t = MailThread.objects.get(messageid=m)
+ refresh_single_thread(t)
+ except Exception, e:
+ # Just ignore it, we'll check again later
+ pass
+
+ return HttpResponse(status=200)
diff --git a/pgcommitfest/settings.py b/pgcommitfest/settings.py
index 44106a7..111d118 100644
--- a/pgcommitfest/settings.py
+++ b/pgcommitfest/settings.py
@@ -163,6 +163,7 @@ ARCHIVES_TIMEOUT=10 # Seconds to wait for calls to the archives
ARCHIVES_SERVER="localhost"
ARCHIVES_PORT="8001"
ARCHIVES_HOST="archives.postgresql.org" # Host: header to send
+ARCHIVES_APIKEY=None
# Email address to pgsql-hackers. Set to something local to test maybe?
HACKERS_EMAIL="pgsql-hackers-testing@localhost"
diff --git a/pgcommitfest/urls.py b/pgcommitfest/urls.py
index 5ca20a7..eafb99c 100644
--- a/pgcommitfest/urls.py
+++ b/pgcommitfest/urls.py
@@ -31,6 +31,7 @@ urlpatterns = [
url(r'^(\d+)/reports/authorstats/$', reports.authorstats),
url(r'^search/$', views.global_search),
url(r'^ajax/(\w+)/$', ajax.main),
+ url(r'^thread_notify/$', views.thread_notify),
url(r'^selectable/', include('selectable.urls')),
diff --git a/tools/commitfest/update_archive_threads.py b/tools/commitfest/update_archive_threads.py
index d32ea1c..19dd221 100755
--- a/tools/commitfest/update_archive_threads.py
+++ b/tools/commitfest/update_archive_threads.py
@@ -19,7 +19,7 @@ django.setup()
from django.db import connection
from pgcommitfest.commitfest.models import MailThread
-from pgcommitfest.commitfest.ajax import _archivesAPI, parse_and_add_attachments
+from pgcommitfest.commitfest.ajax import refresh_single_thread
if __name__ == "__main__":
debug = "--debug" in sys.argv
@@ -32,22 +32,7 @@ if __name__ == "__main__":
logging.debug("Checking for updated mail threads in the archives")
for thread in MailThread.objects.filter(patches__commitfests__status__in=(1,2,3)).distinct():
logging.debug("Checking %s in the archives" % thread.messageid)
- r = sorted(_archivesAPI('/message-id.json/%s' % thread.messageid), key=lambda x: x['date'])
- if thread.latestmsgid != r[-1]['msgid']:
- # There is now a newer mail in the thread!
- logging.info("Thread %s updated" % thread.messageid)
- thread.latestmsgid = r[-1]['msgid']
- thread.latestmessage = r[-1]['date']
- thread.latestauthor = r[-1]['from']
- thread.latestsubject = r[-1]['subj']
- thread.save()
- parse_and_add_attachments(r, thread)
- # Potentially update the last mail date - if there wasn't already a mail on each patch
- # from a *different* thread that had an earlier date.
- for p in thread.patches.filter(lastmail__lt=thread.latestmessage):
- logging.debug("Last mail time updated for %s" % thread.messageid)
- p.lastmail = thread.latestmessage
- p.save()
+ refresh_single_thread(thread)
connection.close()
logging.debug("Done.")