mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-09-16 10:32:10 +00:00
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:
@@ -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[]> {
|
||||
|
||||
Reference in New Issue
Block a user