From 6d22fcb21a6f0bafc206123d23af501697fe6114 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Mon, 16 Jun 2025 11:25:19 +0200 Subject: [PATCH] Round of since/ and before/ URLs to whole days Previously we'd generate links for each individual email, when clicking the link on the emails. This generates a huge number of URLs that contain basically the same thing, which has an adverse effect on both caching and (stupid) bots. So round it off to even days which puts at least some level of a cap on it. Also, when a hit comes in that specifies the full hour, redirect it back to the rounded-off value. --- django/archives/mailarchives/models.py | 4 ++++ django/archives/mailarchives/templates/_message.html | 2 +- .../mailarchives/templates/datelist_topandbottom.html | 4 ++-- django/archives/mailarchives/views.py | 6 ++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/django/archives/mailarchives/models.py b/django/archives/mailarchives/models.py index 44c4469..4a6a055 100644 --- a/django/archives/mailarchives/models.py +++ b/django/archives/mailarchives/models.py @@ -41,6 +41,10 @@ class Message(models.Model): def shortdate(self): return self.date.strftime("%Y%m%d%H%M") + @property + def dateonly(self): + return self.date.strftime("%Y%m%d") + def from_name_only(self): try: return parseaddr(self.mailfrom)[0] diff --git a/django/archives/mailarchives/templates/_message.html b/django/archives/mailarchives/templates/_message.html index b4f42af..5b7404a 100644 --- a/django/archives/mailarchives/templates/_message.html +++ b/django/archives/mailarchives/templates/_message.html @@ -52,7 +52,7 @@ Lists: {%for l in lists %} - {{l.listname}} + {{l.listname}} {%endfor%} diff --git a/django/archives/mailarchives/templates/datelist_topandbottom.html b/django/archives/mailarchives/templates/datelist_topandbottom.html index cd620ca..ccac52a 100644 --- a/django/archives/mailarchives/templates/datelist_topandbottom.html +++ b/django/archives/mailarchives/templates/datelist_topandbottom.html @@ -1,11 +1,11 @@ {%if messages%}

Browse Archives

{%with messages|first as firstmsg%} -Prev +Prev {%endwith%} | {%with messages|last as lastmsg%} -Next +Next {%endwith%} {%endif%} diff --git a/django/archives/mailarchives/views.py b/django/archives/mailarchives/views.py index 1fc1a8a..c1118ac 100644 --- a/django/archives/mailarchives/views.py +++ b/django/archives/mailarchives/views.py @@ -331,6 +331,9 @@ def datelistsincetime(request, listname, year, month, day, hour, minute): ensure_list_permissions(request, l) try: + if int(hour) != 0 or int(minute) != 0: + # "round off" timestamps to the whole day, to reduce the number of unique urls + return HttpResponseRedirect("{}{}{}0000".format(year, month, day)) d = datetime(int(year), int(month), int(day), int(hour), int(minute)) except ValueError: raise Http404("Invalid date format, not found") @@ -352,6 +355,9 @@ def datelistbeforetime(request, listname, year, month, day, hour, minute): ensure_list_permissions(request, l) try: + if int(hour) != 0 or int(minute) != 0: + # "round off" timestamps to the whole day, to reduce the number of unique urls + return HttpResponseRedirect("{}{}{}0000".format(year, month, day)) d = datetime(int(year), int(month), int(day), int(hour), int(minute)) except ValueError: raise Http404("Invalid date format, not found") -- 2.39.5