From 26b9e3b8c1667e1931c16f34ccdd6f3a4ddca2ee Mon Sep 17 00:00:00 2001 From: Josh Creek <8179928+jcreek@users.noreply.github.com> Date: Tue, 15 Sep 2026 17:46:23 +0100 Subject: [PATCH] =?UTF-8?q?perf(pokedex):=20fetch=20dex=20scopes=20with=20?= =?UTF-8?q?the=20pok=C3=A9dex=20row?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit findById made a second round trip for scopes on every page load; embed pokedex_dex_scopes in the select instead. --- src/lib/repositories/PokedexRepository.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/repositories/PokedexRepository.ts b/src/lib/repositories/PokedexRepository.ts index 10b056d..f426582 100644 --- a/src/lib/repositories/PokedexRepository.ts +++ b/src/lib/repositories/PokedexRepository.ts @@ -55,14 +55,16 @@ class PokedexRepository { async findById(id: string): Promise { const { data, error } = await this.supabase .from('pokedexes') - .select('*') + .select('*, pokedex_dex_scopes(dexId)') .eq('id', id) .eq('userId', this.userId) .single(); if (error || !data) return null; - const dexScopesMap = await this.fetchDexScopesMap([data.id]); - return this.transform(data, dexScopesMap.get(data.id) || []); + return this.transform( + data, + (data.pokedex_dex_scopes ?? []).map((scope: { dexId: string }) => scope.dexId) + ); } async findAll(): Promise {