mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(generator): raise enrollment ceiling, add burst guard, stop enqueue loop
ENROLLMENT_DAILY_CAP was 50, so any traffic spike past 50 new users in a day was turned away with a rate_limited card. Raise the default to 500 and add ENROLLMENT_HOURLY_CAP=60. The hourly guard is the one that actually protects the shared PAT: a new user costs ~37 REST calls (p90 ~104) against a 5000/hr budget, and a spike arrives inside an hour rather than spread over a day. Counted off users.enrolled_at, so no schema change. Also stop an unbounded enqueue loop. `name` is drawn inside the composite and never persisted standalone, and `achievements` renders nothing until the user authors one, so their SVG is permanently absent and every request re-enqueued a build that could never produce it. Only self-heal when no build has actually landed, keyed off widget_data for the current hash. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BwMoSbmK77Ph7XaV5YnAdS
This commit is contained in:
@@ -407,6 +407,57 @@ def test_data_unknown_user_when_cap_reached_returns_429(client, monkeypatch):
|
||||
assert dbmod.get_settings("testuser") is None
|
||||
|
||||
|
||||
def test_widget_with_no_output_does_not_reenqueue_forever(client):
|
||||
"""`name` is drawn inside the composite and never persisted standalone, so
|
||||
its SVG is permanently absent. Once a build has landed, requesting it must
|
||||
NOT enqueue another build: every request doing so pins the worker and grows
|
||||
the prefetch queue without bound under load."""
|
||||
dbmod.enroll("alice", {"theme": "dark"})
|
||||
dbmod.put_widget_data("alice", "h1", {"some": "data"})
|
||||
dbmod.put_widgets("alice", "h1", {"composite": "<svg>ready</svg>"})
|
||||
dbmod.point_current_widget("alice", "h1")
|
||||
|
||||
before = dbmod.pending_job_count()
|
||||
for _ in range(5):
|
||||
r = client.get("/api/alice/name.svg")
|
||||
assert r.headers["X-Widget-Status"] == "building"
|
||||
assert dbmod.pending_job_count() == before
|
||||
|
||||
|
||||
def test_missing_widget_still_self_heals_when_no_build_landed(client):
|
||||
"""The self-heal must survive: no widget_data means the build never
|
||||
completed, so one rebuild should still be queued."""
|
||||
dbmod.enroll("bob", {"theme": "dark"})
|
||||
# Drain the enrollment build without it ever persisting widget_data,
|
||||
# i.e. the permanently-failed build the self-heal exists for.
|
||||
job = dbmod.claim_next_job()
|
||||
dbmod.fail_job(job["id"], "boom", retry=False)
|
||||
assert dbmod.pending_job_count() == 0
|
||||
|
||||
r = client.get("/api/bob/grade.svg")
|
||||
assert r.headers["X-Widget-Status"] == "building"
|
||||
assert dbmod.pending_job_count() == 1
|
||||
|
||||
|
||||
def test_data_unknown_user_when_hourly_cap_reached_returns_429(client, monkeypatch):
|
||||
"""The hourly burst guard is what protects the PAT during a launch spike:
|
||||
a day's budget arriving inside one hour would exhaust it."""
|
||||
monkeypatch.setattr(cfg, "ENROLLMENT_DAILY_CAP", 10_000)
|
||||
monkeypatch.setattr(cfg, "ENROLLMENT_HOURLY_CAP", 0)
|
||||
r = client.get("/api/testuser/data")
|
||||
assert r.status_code == 429
|
||||
assert r.get_json()["status"] == "rate_limited"
|
||||
assert dbmod.get_settings("testuser") is None
|
||||
|
||||
|
||||
def test_data_unknown_user_enrolls_when_under_both_caps(client, monkeypatch):
|
||||
monkeypatch.setattr(cfg, "ENROLLMENT_DAILY_CAP", 10_000)
|
||||
monkeypatch.setattr(cfg, "ENROLLMENT_HOURLY_CAP", 10_000)
|
||||
r = client.get("/api/testuser/data")
|
||||
assert r.status_code == 202
|
||||
assert dbmod.get_settings("testuser") is not None
|
||||
|
||||
|
||||
# ---- /api/top-langs compat shim for upstream github-readme-stats URLs ----
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user