Much fresher live data: 8s in-play polling, live-TTL summary fetches
The live staleness bug: liveTick refetched ESPN summaries every 20s but the cache TTL was 5 minutes, so in-play stats/timeline barely moved. Summaries now take a live flag (15s TTL in play), the scoreboard TTL drops 20s->5s, and polling gets three tiers (8s in-play / 20s near kickoff / 10m idle) via a pure, tested cadence module. The football-data fallback is throttled to one attempt per 15s so the 8s cadence can never breach its 10 req/min cap. Enrichment runs every 5m (was 20m); client refetch intervals tighten to 10s (live match page) and 30s (scoreboard). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { POLL_IDLE_MS, POLL_INPLAY_MS, POLL_NEAR_MS, fallbackAllowed, pollDelay } from './cadence';
|
||||
|
||||
describe('pollDelay', () => {
|
||||
it('polls fastest while a match is in play', () => {
|
||||
expect(pollDelay(true, true)).toBe(POLL_INPLAY_MS);
|
||||
expect(pollDelay(true, false)).toBe(POLL_INPLAY_MS);
|
||||
});
|
||||
|
||||
it('polls at the near cadence inside a kickoff window', () => {
|
||||
expect(pollDelay(false, true)).toBe(POLL_NEAR_MS);
|
||||
});
|
||||
|
||||
it('idles when nothing is on', () => {
|
||||
expect(pollDelay(false, false)).toBe(POLL_IDLE_MS);
|
||||
});
|
||||
|
||||
it('tiers are ordered in-play < near < idle', () => {
|
||||
expect(POLL_INPLAY_MS).toBeLessThan(POLL_NEAR_MS);
|
||||
expect(POLL_NEAR_MS).toBeLessThan(POLL_IDLE_MS);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fallbackAllowed', () => {
|
||||
it('blocks attempts inside the throttle interval', () => {
|
||||
expect(fallbackAllowed(1_000_000, 1_010_000)).toBe(false);
|
||||
});
|
||||
|
||||
it('allows attempts once the interval has passed', () => {
|
||||
expect(fallbackAllowed(1_000_000, 1_015_000)).toBe(true);
|
||||
expect(fallbackAllowed(0, 1_000_000)).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps the 8s in-play cadence under the 10 req/min football-data cap', () => {
|
||||
// one attempt per 15s ⇒ 4 req/min even if every tick fails over
|
||||
expect(fallbackAllowed(0, 15_000)).toBe(true);
|
||||
expect(fallbackAllowed(0, 14_999)).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user