Perf: parallelize admin loads + edge-cache /api/brief
Two concrete latency wins found by measuring (server compute is 2-17ms; the time is in the path, not the box): - Admin panel fired its 6 API calls SEQUENTIALLY (await chain) — so it paid the uncached origin round-trip six times back-to-back. Now one Promise.all batch. This is the admin lag. - /api/brief (the home "Gathering the good news…" content) wasn't edge-cached, so a distant anonymous visitor triggered a Cloudflare→residential-origin pull. Same global/shareable boundary as /api/feed: public s-maxage=45 when no prefs/exclude, else private,no-store. (Needs /api/brief added to the CF cache rule path list to take effect at the edge.) Tests: test_brief_cache_boundary. 228 pytest + 11 vitest. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -28,12 +28,22 @@
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await loadStats();
|
||||
feedback = await getJSON('/api/admin/feedback');
|
||||
candidates = await getJSON('/api/admin/candidates');
|
||||
wpPool = await getJSON('/api/admin/word/pool');
|
||||
clientErrors = await getJSON('/api/admin/client-errors');
|
||||
wsThemes = await getJSON('/api/admin/wordsearch/themes');
|
||||
// Load all panels in PARALLEL — these were sequential awaits, so the page
|
||||
// paid the (uncached, origin) round-trip six times back-to-back. One batch
|
||||
// instead of a chain.
|
||||
const [, fb, cand, wp, ce, ws] = await Promise.all([
|
||||
loadStats(),
|
||||
getJSON('/api/admin/feedback'),
|
||||
getJSON('/api/admin/candidates'),
|
||||
getJSON('/api/admin/word/pool'),
|
||||
getJSON('/api/admin/client-errors'),
|
||||
getJSON('/api/admin/wordsearch/themes'),
|
||||
]);
|
||||
feedback = fb;
|
||||
candidates = cand;
|
||||
wpPool = wp;
|
||||
clientErrors = ce;
|
||||
wsThemes = ws;
|
||||
} catch {
|
||||
error = "Couldn't load stats.";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user