mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Merge pull request #2113 from bookwyrm-social/status-priority
Fixes how backdated statuses are prioritized
This commit is contained in:
commit
17864da8a2
2 changed files with 40 additions and 2 deletions
|
@ -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(
|
||||
|
|
|
@ -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 @@ class ActivitystreamsSignals(TestCase):
|
|||
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:
|
||||
|
|
Loading…
Reference in a new issue