fix(search): stop replaying a failed LA-averages request forever
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m12s
PR Checks / Backend Smoke (pull_request) Successful in 9s
PR Checks / Build Backend (no push) (pull_request) Successful in 18s
PR Checks / Build Frontend (no push) (pull_request) Successful in 1m18s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 11s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 18s
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m12s
PR Checks / Backend Smoke (pull_request) Successful in 9s
PR Checks / Build Backend (no push) (pull_request) Successful in 18s
PR Checks / Build Frontend (no push) (pull_request) Successful in 1m18s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 11s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 18s
The search page fetched LA averages with cache: 'force-cache', which serves any stored response, however old, without asking the server. One failed request (a staging deploy restart; the July proxy outage) was stored and replayed on every later visit, and the error was swallowed, so the "vs LA avg" delta silently vanished from every secondary row in that browser. A Playwright profile still held a 500 dated 5 July. The default cache mode honours the API's Cache-Control (five minutes), so a good answer is still reused and an error never is. Browsers holding a stored failure recover on their next visit. A journey now checks that a mainstream secondary's row shows the comparison: nothing did, which is how it could go missing unnoticed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c931d1078c
commit
59ea8a4bdd
3 files changed
+50
-3
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||
import { HomeView } from '@/components/HomeView';
|
||||
import { fetchSchools } from '@/lib/api';
|
||||
import { fetchLAaverages, fetchSchools } from '@/lib/api';
|
||||
import { primaryFixture } from '../support/schoolFixtures';
|
||||
import type { SchoolsResponse, School } from '@/lib/types';
|
||||
|
||||
@@ -84,3 +84,23 @@ test('failed map requests can be retried by reopening the map', async () => {
|
||||
expect(fetchSchools).toHaveBeenCalledTimes(2);
|
||||
expect(screen.getByTestId('map')).toHaveTextContent('Retry result');
|
||||
});
|
||||
|
||||
test('LA averages are not fetched with force-cache, so one failure is not replayed for good', async () => {
|
||||
// force-cache serves any stored response, however old, without asking the
|
||||
// server. A request that failed once (a staging deploy restart, the July
|
||||
// proxy outage) was stored and replayed on every later visit, and the
|
||||
// "vs LA avg" delta vanished from every secondary row in that browser.
|
||||
// The default mode honours the API's Cache-Control and never reuses an
|
||||
// error.
|
||||
params = new URLSearchParams('search=high');
|
||||
const secondary: SchoolsResponse = {
|
||||
...response('Alpha High'),
|
||||
schools: [{ ...primaryFixture.schoolInfo, school_name: 'Alpha High', phase: 'Secondary', attainment_8_score: 50 }],
|
||||
};
|
||||
render(<HomeView initialSchools={secondary} filters={filters} />);
|
||||
await act(async () => {});
|
||||
expect(fetchLAaverages).toHaveBeenCalled();
|
||||
for (const [options] of jest.mocked(fetchLAaverages).mock.calls) {
|
||||
expect(options?.cache).not.toBe('force-cache');
|
||||
}
|
||||
});
|
||||
@@ -358,10 +358,14 @@ export function HomeView({ initialSchools, filters, totalSchools, howItWorks, ed
|
||||
return () => controller.abort();
|
||||
}, [resultsView, searchParams, initialSchools.schools]);
|
||||
|
||||
// Fetch LA averages when secondary or mixed schools are visible
|
||||
// Fetch LA averages when secondary or mixed schools are visible. Default
|
||||
// cache mode, never force-cache: force-cache replays any stored response
|
||||
// without asking the server, so one failed request (a deploy restart) hid
|
||||
// every "vs LA avg" delta in that browser for good. The API's Cache-Control
|
||||
// already lets the browser reuse a good answer for five minutes.
|
||||
useEffect(() => {
|
||||
if (!isSecondaryView && !isMixedView) return;
|
||||
fetchLAaverages({ cache: 'force-cache' })
|
||||
fetchLAaverages()
|
||||
.then(data => setLaAverages(data.secondary.attainment_8_by_la))
|
||||
.catch(() => {});
|
||||
}, [isSecondaryView, isMixedView]);
|
||||
|
||||
Reference in new issue
Block a user