Private
Public Access
Enqueue the initial feed fetch instead of running it inline (T3)
add_feed ran fetch_and_ingest synchronously during the POST request, so a slow or large feed tied up a Gunicorn worker for the duration of the fetch (up to the 15s HTTP timeout, plus parse/ingest time) and a user could repeat it with distinct URLs to reduce request capacity. The subscription is now created synchronously as before, but the first fetch is dispatched via fetch_feed.delay() — the same task the periodic poll uses, so the save/error bookkeeping is unchanged. The user sees an immediate redirect with a message that the fetch is in progress rather than waiting on it in the request/response cycle. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7bb981b545
commit
0bfe9c8076
2 files changed
+19
-22
No files matched your search
+8
-3
@@ -54,7 +54,11 @@ GOOD_FEED_XML = """<?xml version="1.0"?>
|
||||
|
||||
@pytest.mark.django_db
|
||||
@responses.activate
|
||||
def test_add_feed_view_subscribes_and_fetches_immediately(client, two_users):
|
||||
def test_add_feed_view_subscribes_and_enqueues_the_initial_fetch(client, two_users):
|
||||
"""The subscription is created synchronously; the first fetch is
|
||||
dispatched via fetch_feed.delay() (T3) rather than run inline — in
|
||||
tests CELERY_TASK_ALWAYS_EAGER still runs it immediately, so the
|
||||
article it ingests is visible by the time the response returns."""
|
||||
alice, _ = two_users
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
responses.add(responses.GET, "https://example.com/feed.xml", body=GOOD_FEED_XML, status=200)
|
||||
@@ -62,9 +66,10 @@ def test_add_feed_view_subscribes_and_fetches_immediately(client, two_users):
|
||||
response = client.post(reverse("feeds:add_feed"), {"feed_url": "https://example.com/feed.xml"})
|
||||
|
||||
assert response.status_code == 302
|
||||
assert Subscription.objects.filter(
|
||||
subscription = Subscription.objects.get(
|
||||
user=alice, feed__feed_url="https://example.com/feed.xml"
|
||||
).exists()
|
||||
)
|
||||
assert subscription.feed.articles.filter(guid="guid-1").exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
Reference in new issue
Block a user