perf(pokedex): fetch dex scopes with the pokédex row

findById made a second round trip for scopes on every page load; embed
pokedex_dex_scopes in the select instead.
This commit is contained in:
Josh Creek
2026-09-15 17:46:23 +01:00
parent acaf760b36
commit 26b9e3b8c1
+5 -3
View File
@@ -55,14 +55,16 @@ class PokedexRepository {
async findById(id: string): Promise<Pokedex | null> {
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<Pokedex[]> {