Private
Public Access
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>
This commit is contained in:
1 parent
a1ea2e5662
commit
dc8b9ff83b
11 files changed
+203
-20
No files matched your search
+8
-4
@@ -8,6 +8,7 @@ from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
|
||||
from apps.articles.tasks import apply_filter_rules_for_feed
|
||||
from apps.core.models import SiteSettings
|
||||
|
||||
from .models import Feed
|
||||
from .opml import import_opml
|
||||
@@ -32,12 +33,15 @@ def poll_due_feeds():
|
||||
"""
|
||||
now = timezone.now()
|
||||
claim_stale_before = now - timedelta(minutes=CLAIM_STALE_MINUTES)
|
||||
# Loaded once per call, not per feed — the interval is site-wide
|
||||
# (apps.core.models.SiteSettings), so every feed below shares it.
|
||||
configured_interval = SiteSettings.load().fetch_interval_minutes
|
||||
due_feed_ids = [
|
||||
feed.id
|
||||
for feed in Feed.objects.filter(is_active=True).only(
|
||||
"id", "last_fetched_at", "fetch_interval_minutes", "fetch_error_count"
|
||||
"id", "last_fetched_at", "fetch_error_count"
|
||||
)
|
||||
if _is_due(feed)
|
||||
if _is_due(feed, configured_interval)
|
||||
]
|
||||
claimed_ids = []
|
||||
for feed_id in due_feed_ids:
|
||||
@@ -57,10 +61,10 @@ def poll_due_feeds():
|
||||
return len(claimed_ids)
|
||||
|
||||
|
||||
def _is_due(feed: Feed) -> bool:
|
||||
def _is_due(feed: Feed, configured_interval_minutes: int) -> bool:
|
||||
if feed.last_fetched_at is None:
|
||||
return True
|
||||
interval = effective_interval_minutes(feed)
|
||||
interval = effective_interval_minutes(feed, configured_interval_minutes)
|
||||
return feed.last_fetched_at <= timezone.now() - timedelta(minutes=interval)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user