Files
Evection/apps/feeds/models.py
T
ksmithandClaude Sonnet 5 dc8b9ff83b Make the feed-poll interval site-wide instead of per-feed
Replaces Feed.fetch_interval_minutes with a single admin-editable
SiteSettings.fetch_interval_minutes (apps.core), following the same
singleton-row pattern as accounts.SetupLock. Per-feed error backoff is
unchanged — only the configured baseline interval is now shared across
every feed, loaded once per poll_due_feeds run rather than queried per
feed. EVECTION_MIN_FETCH_INTERVAL_MINUTES keeps working as the floor
underneath it.

SiteSettings is registered in Django admin as a singleton: "Add" is
only offered when no row exists yet, and delete is always refused.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-31 12:59:47 -06:00

81 lines
3.0 KiB
Python

from django.conf import settings
from django.db import models
class Feed(models.Model):
"""A single polled RSS/Atom source, shared across every subscriber.
One row per feed_url regardless of how many users subscribe to it — the
fetch pipeline polls each feed exactly once and every Subscription below
just points at the same Feed/Article data. Never add per-user fetching.
"""
STATUS_PENDING = "pending"
STATUS_OK = "ok"
STATUS_NOT_MODIFIED = "not_modified"
STATUS_ERROR = "error"
STATUS_CHOICES = [
(STATUS_PENDING, "Pending"),
(STATUS_OK, "OK"),
(STATUS_NOT_MODIFIED, "Not modified"),
(STATUS_ERROR, "Error"),
]
feed_url = models.URLField(max_length=1000, unique=True)
site_url = models.URLField(max_length=1000, blank=True)
title = models.CharField(max_length=500, blank=True)
favicon_url = models.URLField(max_length=1000, blank=True)
etag = models.CharField(max_length=255, blank=True)
last_modified = models.CharField(max_length=255, blank=True)
last_fetched_at = models.DateTimeField(null=True, blank=True)
last_fetch_status = models.CharField(
max_length=20, choices=STATUS_CHOICES, default=STATUS_PENDING
)
last_error_message = models.TextField(blank=True)
# The poll interval itself is site-wide now (apps.core.models.
# SiteSettings), not per-feed — only the error-driven backoff on top
# of it still varies per feed (see apps.feeds.services.fetcher.
# effective_interval_minutes).
fetch_error_count = models.PositiveIntegerField(default=0)
is_active = models.BooleanField(default=True)
# Set by poll_due_feeds' atomic claim (an UPDATE ... WHERE clause, not
# select_for_update — Celery Beat and fetch_feed run in separate
# transactions) and cleared once fetch_feed finishes, so overlapping
# beat ticks or a fetch that runs long can't both dispatch the same
# feed. A claim older than CLAIM_STALE_MINUTES (tasks.py) is treated as
# abandoned and can be reclaimed, so a worker dying mid-fetch doesn't
# wedge the feed forever.
claimed_at = models.DateTimeField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title or self.feed_url
class Subscription(models.Model):
"""Per-user join between a User and a shared Feed."""
user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="subscriptions"
)
feed = models.ForeignKey(Feed, on_delete=models.CASCADE, related_name="subscriptions")
custom_title = models.CharField(max_length=500, blank=True)
order = models.PositiveIntegerField(default=0)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = [("user", "feed")]
ordering = ["order", "id"]
def __str__(self):
return self.custom_title or self.feed.title or self.feed.feed_url
@property
def display_title(self):
return self.custom_title or self.feed.title or self.feed.feed_url