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:
@@ -234,3 +234,54 @@ describe('compact grid reads', () => {
|
||||
expect(selection?.args).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CombinedDataRepository.isEntryInDex', () => {
|
||||
it('accepts an entry the scoped dex lists, without reading the whole dex', async () => {
|
||||
const { supabase, queries } = createSupabaseStub((table) =>
|
||||
table === 'game_pokedex_entry_details'
|
||||
? { data: [{ id: 25 }], error: null }
|
||||
: { data: [], error: null }
|
||||
);
|
||||
const repo = new CombinedDataRepository(supabase, 'user-1', 'dex-1');
|
||||
|
||||
await expect(repo.isEntryInDex(25, false, 'Black', ['black-unova'])).resolves.toBe(true);
|
||||
|
||||
const [dexEntries] = queryFor(queries, 'game_pokedex_entry_details');
|
||||
expect(hasCall(dexEntries, 'eq', ['id', 25])).toBe(true);
|
||||
expect(hasCall(dexEntries, 'eq', ['isDefaultForm', true])).toBe(true);
|
||||
expect(hasCall(dexEntries, 'limit', [1])).toBe(true);
|
||||
// A membership check must not page the dex the way the grid read does.
|
||||
expect(dexEntries.calls.some((c) => c.method === 'range')).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts a named form a game-scoped form dex supplements from pokedex_entries', async () => {
|
||||
const { supabase, queries } = createSupabaseStub((table) =>
|
||||
table === 'pokedex_entries' ? { data: [{ id: 99 }], error: null } : { data: [], error: null }
|
||||
);
|
||||
const repo = new CombinedDataRepository(supabase, 'user-1', 'dex-1');
|
||||
|
||||
await expect(repo.isEntryInDex(99, true, 'Scarlet', ['scarlet-paldea'])).resolves.toBe(true);
|
||||
|
||||
const [forms] = queryFor(queries, 'pokedex_entries');
|
||||
expect(hasCall(forms, 'not', ['form', 'is', null])).toBe(true);
|
||||
expect(hasCall(forms, 'contains', ['gamesToCatchIn', ['Scarlet']])).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects an entry that is in neither the scoped dex nor its form supplement', async () => {
|
||||
const { supabase } = createSupabaseStub();
|
||||
const repo = new CombinedDataRepository(supabase, 'user-1', 'dex-1');
|
||||
|
||||
await expect(repo.isEntryInDex(1, true, 'Scarlet', ['scarlet-paldea'])).resolves.toBe(false);
|
||||
});
|
||||
|
||||
it('checks an unscoped dex against the game filter alone', async () => {
|
||||
const { supabase, queries } = createSupabaseStub(() => ({ data: [{ id: 25 }], error: null }));
|
||||
const repo = new CombinedDataRepository(supabase, 'user-1', 'dex-1');
|
||||
|
||||
await expect(repo.isEntryInDex(25, true, 'Red', [])).resolves.toBe(true);
|
||||
|
||||
const [entries] = queryFor(queries, 'pokedex_entries');
|
||||
expect(hasCall(entries, 'contains', ['gamesToCatchIn', ['Red']])).toBe(true);
|
||||
expect(mentionsIsDefaultForm(entries)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user