mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-09-16 18:42:03 +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> {
|
async findById(id: string): Promise<Pokedex | null> {
|
||||||
const { data, error } = await this.supabase
|
const { data, error } = await this.supabase
|
||||||
.from('pokedexes')
|
.from('pokedexes')
|
||||||
.select('*')
|
.select('*, pokedex_dex_scopes(dexId)')
|
||||||
.eq('id', id)
|
.eq('id', id)
|
||||||
.eq('userId', this.userId)
|
.eq('userId', this.userId)
|
||||||
.single();
|
.single();
|
||||||
|
|
||||||
if (error || !data) return null;
|
if (error || !data) return null;
|
||||||
const dexScopesMap = await this.fetchDexScopesMap([data.id]);
|
return this.transform(
|
||||||
return this.transform(data, dexScopesMap.get(data.id) || []);
|
data,
|
||||||
|
(data.pokedex_dex_scopes ?? []).map((scope: { dexId: string }) => scope.dexId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(): Promise<Pokedex[]> {
|
async findAll(): Promise<Pokedex[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user