Round of since/ and before/ URLs to whole days
authorMagnus Hagander <magnus@hagander.net>
Mon, 16 Jun 2025 09:25:19 +0000 (11:25 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 16 Jun 2025 09:27:49 +0000 (11:27 +0200)
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
django/archives/mailarchives/templates/_message.html
django/archives/mailarchives/templates/datelist_topandbottom.html
django/archives/mailarchives/views.py

index 44c4469c097546b743a3fb1e5fbe8f1dcdf3b6c2..4a6a055db0ed106b7011a673eee4dca2ea4135c5 100644 (file)
@@ -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]
index b4f42af04cb384747375459985bf3e11c71f12a6..5b7404a0de3c0e043ef7f7f5167659dec7de6451 100644 (file)
@@ -52,7 +52,7 @@
       <th scope="row">Lists:</th>
       <td>
         {%for l in lists %}
-          <span class="listname"><a href="/list/{{l.listname}}/since/{{msg.shortdate}}">{{l.listname}}</a></span>
+          <span class="listname"><a href="/list/{{l.listname}}/since/{{msg.dateonly}}0000">{{l.listname}}</a></span>
         {%endfor%}
       </td>
     </tr>
index cd620ca2cb71b5b6a5de61d180c6b34bbcdfe01f..ccac52a67cf07b007d5ed7eb9f91ccbaab05de97 100644 (file)
@@ -1,11 +1,11 @@
 {%if messages%}
 <h3>Browse Archives</h3>
 {%with messages|first as firstmsg%}
-<a href="/list/{{list.listname}}/before/{{firstmsg.shortdate}}" rel="nofollow">Prev</a>
+<a href="/list/{{list.listname}}/before/{{firstmsg.dateonly}}0000" rel="nofollow">Prev</a>
 {%endwith%}
 |
 {%with messages|last as lastmsg%}
-<a href="/list/{{list.listname}}/since/{{lastmsg.shortdate}}" rel="nofollow">Next</a>
+<a href="/list/{{list.listname}}/since/{{lastmsg.dateonly}}0000" rel="nofollow">Next</a>
 {%endwith%}
 {%endif%}
 
index 1fc1a8aec16c75832bd454524a69ea1009e42369..c1118ac69cd506805285732a52c6848cce731124 100644 (file)
@@ -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")