Files
ksmithandClaude Sonnet 5.5 e5f1277014 Batch feed ingestion, add a readiness check, fail open without Redis (C2, C8)
Ingestion did a get_or_create per entry. It now prefetches existing
articles for the poll in one query, bulk-inserts new ones and
bulk-updates changed ones (falling back to row-by-row only if a
concurrent fetch wins a race), and dispatches rule evaluation in
bounded chunks so a huge first fetch is several small tasks.

/health/ stays a DB-only liveness check (upgrade.sh gates on it right
after restart). New /health/ready/ also checks Redis and that
poll_due_feeds ticked within five minutes — proving beat and a worker
are both alive — and returns 503 with per-check detail otherwise.

The sidebar unread-count cache and login throttle now degrade instead
of erroring when Redis is unreachable: every authenticated page and
every login would otherwise 500 during a cache outage. Found while
verifying in a sandbox with no Redis.

Also includes the dashboard's oldest-article metric (core/views.py).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-01 08:51:20 -07:00

50 lines
1.8 KiB
Python

from django.conf import settings
from django.shortcuts import redirect
from django.urls import reverse
from .models import User
_SETUP_EXEMPT_PREFIXES = (settings.STATIC_URL,)
class SetupWizardMiddleware:
"""Force every request to the first-run setup wizard until an account exists.
Once any User row exists, /setup/ becomes unreachable again (see the
setup view), mirroring FreshRSS's one-time install wizard. The "a user
exists" check only ever flips false -> true for the lifetime of an
instance, so it's cached per-process after the first positive result to
avoid a query on every request.
"""
_a_user_exists = False
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
path = request.path
if not path.startswith(_SETUP_EXEMPT_PREFIXES) and path not in _setup_exempt_paths():
if not SetupWizardMiddleware._a_user_exists:
SetupWizardMiddleware._a_user_exists = User.objects.exists()
setup_url = reverse("accounts:setup")
if path != setup_url and not SetupWizardMiddleware._a_user_exists:
return redirect(setup_url)
return self.get_response(request)
def _setup_exempt_paths():
"""Routes that must work even before the instance's first-run setup is
complete: the manifest/service worker/offline page (a browser can fetch
these on any visit, setup page included — it extends the same base
template) and the health check (ops tooling, e.g. scripts/upgrade.sh,
needs it reachable immediately after a fresh deploy, before anyone has
created an account)."""
return {
reverse("pwa:manifest"),
reverse("pwa:service_worker"),
reverse("pwa:offline"),
reverse("core:health"),
reverse("core:health_ready"),
}