Repository: bookwyrm-social/bookwyrm

Issue:
Registration Confirmation Code emails can take a long time to arrive
> I'm not receiving the emailed confirmation code after joining the site. I've resent it a couple of times and have checked my Spam folder, to no avail. 


Discussion:
On a large instance like bookwyrm.social, the task queuer gets periodically clogged up and high priority tasks, like sending confirmation emails, take a long time to run. The emails usually come through eventually, but it's reasonable for users to expect much more timely responses. 

If you haven't gotten your email, though, please let me know!

Resolving patch:
diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py
--- a/bookwyrm/activitystreams.py
+++ b/bookwyrm/activitystreams.py
@@ -298,8 +298,9 @@ def add_status_on_create_command(sender, instance, created):
     priority = HIGH
     # check if this is an old status, de-prioritize if so
     # (this will happen if federation is very slow, or, more expectedly, on csv import)
-    one_day = 60 * 60 * 24
-    if (instance.created_date - instance.published_date).seconds > one_day:
+    if instance.published_date < timezone.now() - timedelta(
+        days=1
+    ) or instance.created_date < instance.published_date - timedelta(days=1):
         priority = LOW
 
     add_status_task.apply_async(


Test patch:
diff --git a/bookwyrm/tests/activitystreams/test_signals.py b/bookwyrm/tests/activitystreams/test_signals.py
--- a/bookwyrm/tests/activitystreams/test_signals.py
+++ b/bookwyrm/tests/activitystreams/test_signals.py
@@ -1,6 +1,10 @@
 """ testing activitystreams """
+from datetime import datetime, timedelta
 from unittest.mock import patch
+
 from django.test import TestCase
+from django.utils import timezone
+
 from bookwyrm import activitystreams, models
 
 
@@ -62,6 +66,39 @@ def test_add_status_on_create_created(self, *_):
         self.assertEqual(args["args"][0], status.id)
         self.assertEqual(args["queue"], "high_priority")
 
+    def test_add_status_on_create_created_low_priority(self, *_):
+        """a new statuses has entered"""
+        # created later than publication
+        status = models.Status.objects.create(
+            user=self.remote_user,
+            content="hi",
+            privacy="public",
+            created_date=datetime(2022, 5, 16, tzinfo=timezone.utc),
+            published_date=datetime(2022, 5, 14, tzinfo=timezone.utc),
+        )
+        with patch("bookwyrm.activitystreams.add_status_task.apply_async") as mock:
+            activitystreams.add_status_on_create_command(models.Status, status, False)
+
+        self.assertEqual(mock.call_count, 1)
+        args = mock.call_args[1]
+        self.assertEqual(args["args"][0], status.id)
+        self.assertEqual(args["queue"], "low_priority")
+
+        # published later than yesterday
+        status = models.Status.objects.create(
+            user=self.remote_user,
+            content="hi",
+            privacy="public",
+            published_date=timezone.now() - timedelta(days=1),
+        )
+        with patch("bookwyrm.activitystreams.add_status_task.apply_async") as mock:
+            activitystreams.add_status_on_create_command(models.Status, status, False)
+
+        self.assertEqual(mock.call_count, 1)
+        args = mock.call_args[1]
+        self.assertEqual(args["args"][0], status.id)
+        self.assertEqual(args["queue"], "low_priority")
+
     def test_populate_streams_on_account_create_command(self, *_):
         """create streams for a user"""
         with patch("bookwyrm.activitystreams.populate_stream_task.delay") as mock: