Racepicks: Fetch races and remove expanding of races/drivers (already fetched separately)

This commit is contained in:
2025-01-26 14:13:10 +01:00
parent 341c831670
commit 7bd8c6613b

View File

@ -3,10 +3,12 @@ import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ fetch, locals }) => { export const load: PageServerLoad = async ({ fetch, locals }) => {
const fetch_racepicks = async (): Promise<RacePick[]> => { const fetch_racepicks = async (): Promise<RacePick[]> => {
// PXX/DNF is not expanded, as we have the drivers anyways (for guessing) // Don't expand race/pxx/dnf since we already fetched those
const racepicks: RacePick[] = await locals.pb const racepicks: RacePick[] = await locals.pb
.collection("racepicks") .collection("racepicks")
.getFullList({ fetch: fetch, expand: "user,race" }); .getFullList({ fetch: fetch, expand: "user" });
// TODO: Fill in the expanded race pictogram_url fields
return racepicks; return racepicks;
}; };
@ -15,13 +17,19 @@ export const load: PageServerLoad = async ({ fetch, locals }) => {
const currentrace: Race[] = await locals.pb.collection("currentrace").getFullList(); const currentrace: Race[] = await locals.pb.collection("currentrace").getFullList();
// The currentrace collection either has a single or no entries // The currentrace collection either has a single or no entries
return currentrace[0] ?? null; if (currentrace.length == 0) return null;
currentrace[0].pictogram_url = await locals.pb.files.getURL(
currentrace[0],
currentrace[0].pictogram,
);
return currentrace[0];
}; };
const fetch_raceresults = async (): Promise<RaceResult[]> => { const fetch_raceresults = async (): Promise<RaceResult[]> => {
const raceresults: RaceResult[] = await locals.pb // Don't expand races/pxxs/dnfs since we already fetched those
.collection("raceresults") const raceresults: RaceResult[] = await locals.pb.collection("raceresults").getFullList();
.getFullList({ expand: "race,pxxs,dnfs" });
return raceresults; return raceresults;
}; };
@ -40,10 +48,25 @@ export const load: PageServerLoad = async ({ fetch, locals }) => {
return drivers; return drivers;
}; };
// TODO: Duplicated code from data/season/+layout.server.ts
const fetch_races = async (): Promise<Race[]> => {
const races: Race[] = await locals.pb.collection("races").getFullList({
sort: "+step",
fetch: fetch,
});
races.map((race: Race) => {
race.pictogram_url = locals.pb.files.getURL(race, race.pictogram);
});
return races;
};
return { return {
racepicks: await fetch_racepicks(), racepicks: await fetch_racepicks(),
currentrace: await fetch_currentrace(), currentrace: await fetch_currentrace(),
raceresults: await fetch_raceresults(), raceresults: await fetch_raceresults(),
drivers: await fetch_drivers(), drivers: await fetch_drivers(),
races: await fetch_races(),
}; };
}; };