mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-09-18 19:42:04 +00:00
fix(pokedex): open detail cards without a per-card round trip
Since the grid transport change, opening a Pokémon fetched /api/pokedexes/[id]/entries/[entryId]. That request re-scanned the whole dex to authorise one entry, on top of an auth call and an ownership query, and production runs its functions in a different region from the database — so each card took seconds to fill in. The page's 60-second reconcile also wiped the detail cache, making cards refetch about once a minute. Details are catalog text plus personal notes, so the dex is now read once per account/dex in the background at the interactive/idle boundary and fills that cache; a card opens straight from memory. That read reuses the existing combined-data endpoint, which gains an opt-out for its count query since a caller taking every row already knows the total. The per-entry endpoint stays as the fallback for a card opened before the background read lands, and now checks membership for the single entry instead of materialising the dex. Catch status still comes from the live grid row and any queued write, so a cached detail cannot show stale progress. The packed grid transport and virtualised rendering are unchanged.
This commit is contained in:
@@ -41,6 +41,14 @@ const errors = [];
|
||||
page.on('pageerror', (error) => errors.push(error.message));
|
||||
const requests = [];
|
||||
page.on('request', (request) => requests.push(new URL(request.url()).pathname));
|
||||
const primedDetails = () =>
|
||||
requests.filter((path) => /\/api\/pokedexes\/[^/]+\/combined-data$/.test(path)).length;
|
||||
// Details are read once per dex at the idle boundary, so allow for a slow idle callback.
|
||||
async function waitForDetailPrime() {
|
||||
const deadline = Date.now() + 15_000;
|
||||
while (primedDetails() === 0 && Date.now() < deadline) await page.waitForTimeout(100);
|
||||
assert.equal(primedDetails(), 1, 'Details must be read exactly once for the dex');
|
||||
}
|
||||
const results = [];
|
||||
try {
|
||||
for (const dex of fixture.dexes) {
|
||||
@@ -61,18 +69,25 @@ try {
|
||||
assert.ok(stats.cells <= 180, `Mounted cells: ${stats.cells}`);
|
||||
assert.ok(stats.dom < 2500, `DOM elements: ${stats.dom}`);
|
||||
assert.ok(stats.cls <= 0.1, `CLS: ${stats.cls}`);
|
||||
assert.equal(
|
||||
requests.filter((path) => /\/api\/pokedexes\/[^/]+\/(grid|combined-data)$/.test(path)).length,
|
||||
0
|
||||
);
|
||||
// The grid ships with the page, so re-fetching it would be redundant. The details read is
|
||||
// deliberate: it is what lets a card open without a round trip of its own.
|
||||
assert.equal(requests.filter((path) => /\/api\/pokedexes\/[^/]+\/grid$/.test(path)).length, 0);
|
||||
await waitForDetailPrime();
|
||||
assert.equal(await page.locator('button button').count(), 0);
|
||||
await page.screenshot({ path: `${directory}/${dex.gameScope ? 'scoped' : 'national'}.png` });
|
||||
const first = page.locator('[data-entry-index="0"]');
|
||||
const entryId = await first.getAttribute('data-entry-id');
|
||||
const notes = await readJson(`/api/pokedexes/${dex.id}/entries/${entryId}`);
|
||||
const openedWith = requests.filter((path) => path.endsWith(`/entries/${entryId}`)).length;
|
||||
await first.click();
|
||||
const modal = page.getByRole('dialog', { name: 'Pokémon details' });
|
||||
await modal.getByLabel('Notes:', { exact: true }).waitFor();
|
||||
// Primed details mean opening a card costs no request of its own.
|
||||
assert.equal(
|
||||
requests.filter((path) => path.endsWith(`/entries/${entryId}`)).length,
|
||||
openedWith,
|
||||
'Opening a card must not fetch its details separately'
|
||||
);
|
||||
assert.equal(
|
||||
await modal.getByLabel('Notes:', { exact: true }).inputValue(),
|
||||
notes.catchRecord.personalNotes
|
||||
|
||||
Reference in New Issue
Block a user