diff --git a/package-lock.json b/package-lock.json index 1b28bff..cb7d5d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,8 +16,8 @@ "@types/alpinejs": "^3.13.10", "@types/alpinejs__collapse": "^3.13.4", "alpinejs": "^3.14.1", - "astro": "^4.13.1", - "tailwindcss": "^3.4.7" + "astro": "^4.13.2", + "tailwindcss": "^3.4.9" } }, "node_modules/@alloc/quick-lru": { @@ -58,9 +58,9 @@ } }, "node_modules/@astrojs/compiler": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/@astrojs/compiler/-/compiler-2.10.0.tgz", - "integrity": "sha512-V8ym+4kYCKmMeSdfDvm/SrlmUlKLkKzfWV3cKyiStEKW/D+YsXaQiBZcSCtuKXq8aQhsDw9HtCTZilhEMBX+BA==" + "version": "2.10.2", + "resolved": "https://registry.npmjs.org/@astrojs/compiler/-/compiler-2.10.2.tgz", + "integrity": "sha512-bvH+v8AirwpRWCkYJEyWYdc5Cs/BjG2ZTxIJzttHilXgfKJAdW2496KsUQKzf5j2tOHtaHXKKn9hb9WZiBGpEg==" }, "node_modules/@astrojs/db": { "version": "0.12.0", @@ -1661,9 +1661,9 @@ ] }, "node_modules/@shikijs/core": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.12.0.tgz", - "integrity": "sha512-mc1cLbm6UQ8RxLc0dZES7v5rkH+99LxQp/ZvTqV3NLyYsO/fD6JhEflP1H5b2SDq9gI0+0G36AVZWxvounfR9w==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/@shikijs/core/-/core-1.12.1.tgz", + "integrity": "sha512-biCz/mnkMktImI6hMfMX3H9kOeqsInxWEyCHbSlL8C/2TR1FqfmGxTLRNwYCKsyCyxWLbB8rEqXRVZuyxuLFmA==", "dependencies": { "@types/hast": "^3.0.4" } @@ -1930,11 +1930,11 @@ } }, "node_modules/astro": { - "version": "4.13.1", - "resolved": "https://registry.npmjs.org/astro/-/astro-4.13.1.tgz", - "integrity": "sha512-VnMjAc+ykFsIVjgbu9Mt/EA1fMIcPMXbU89h3ATwGOzSIKDsQH72bDgfJkWiwk6u0OE90GeP5EPhAT28Twf9oA==", + "version": "4.13.2", + "resolved": "https://registry.npmjs.org/astro/-/astro-4.13.2.tgz", + "integrity": "sha512-bdfUV6zfOWOV/IbROqVx+1cuAFXY0PZpVxr4JO9YxCKa5AfQRR8RKXJ2k8QUjalA6dmxQ9FgAQw3FRrzHVOGEQ==", "dependencies": { - "@astrojs/compiler": "^2.10.0", + "@astrojs/compiler": "^2.10.1", "@astrojs/internal-helpers": "0.4.1", "@astrojs/markdown-remark": "5.2.0", "@astrojs/telemetry": "3.1.0", @@ -1983,7 +1983,7 @@ "prompts": "^2.4.2", "rehype": "^13.0.1", "semver": "^7.6.3", - "shiki": "^1.12.0", + "shiki": "^1.12.1", "string-width": "^7.2.0", "strip-ansi": "^7.1.0", "tsconfck": "^3.1.1", @@ -5632,11 +5632,11 @@ } }, "node_modules/shiki": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/shiki/-/shiki-1.12.0.tgz", - "integrity": "sha512-BuAxWOm5JhRcbSOl7XCei8wGjgJJonnV0oipUupPY58iULxUGyHhW5CF+9FRMuM1pcJ5cGEJGll1LusX6FwpPA==", + "version": "1.12.1", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-1.12.1.tgz", + "integrity": "sha512-nwmjbHKnOYYAe1aaQyEBHvQymJgfm86ZSS7fT8OaPRr4sbAcBNz7PbfAikMEFSDQ6se2j2zobkXvVKcBOm0ysg==", "dependencies": { - "@shikijs/core": "1.12.0", + "@shikijs/core": "1.12.1", "@types/hast": "^3.0.4" } }, @@ -5856,9 +5856,9 @@ } }, "node_modules/tailwindcss": { - "version": "3.4.7", - "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.7.tgz", - "integrity": "sha512-rxWZbe87YJb4OcSopb7up2Ba4U82BoiSGUdoDr3Ydrg9ckxFS/YWsvhN323GMcddgU65QRy7JndC7ahhInhvlQ==", + "version": "3.4.9", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.9.tgz", + "integrity": "sha512-1SEOvRr6sSdV5IDf9iC+NU4dhwdqzF4zKKq3sAbasUWHEM6lsMhX+eNN5gkPx1BvLFEnZQEUFbXnGj8Qlp83Pg==", "dependencies": { "@alloc/quick-lru": "^5.2.0", "arg": "^5.0.2", diff --git a/package.json b/package.json index a083b43..0ff367c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "@types/alpinejs": "^3.13.10", "@types/alpinejs__collapse": "^3.13.4", "alpinejs": "^3.14.1", - "astro": "^4.13.1", - "tailwindcss": "^3.4.7" + "astro": "^4.13.2", + "tailwindcss": "^3.4.9" } } diff --git a/src/pages/shared-subsessions.astro b/src/pages/shared-subsessions.astro index df09daa..9203e30 100644 --- a/src/pages/shared-subsessions.astro +++ b/src/pages/shared-subsessions.astro @@ -26,17 +26,19 @@ const sharedRaceSessions = await db ) .having(({ count }) => gt(count, 1)); const sharedSubsessionIds = sharedRaceSessions.map((v) => v.subsession_id); -const sharedSubsessions = await db - .select() - .from(Subsession) - .where(sql`${Subsession.subsession_id} IN ${sharedSubsessionIds}`) - .orderBy(desc(Subsession.subsession_id)); -const sharedSubsessionRaceResults = await db - .select() - .from(SubsessionRaceResults) - .where( - sql`${SubsessionRaceResults.cust_id} IN ${userIds} AND ${SubsessionRaceResults.simsession_number} = 0 AND ${SubsessionRaceResults.subsession_id} IN ${sharedSubsessionIds}` - ); +const [sharedSubsessions, sharedSubsessionRaceResults] = await db.batch([ + db + .select() + .from(Subsession) + .where(sql`${Subsession.subsession_id} IN ${sharedSubsessionIds}`) + .orderBy(desc(Subsession.subsession_id)), + db + .select() + .from(SubsessionRaceResults) + .where( + sql`${SubsessionRaceResults.cust_id} IN ${userIds} AND ${SubsessionRaceResults.simsession_number} = 0 AND ${SubsessionRaceResults.subsession_id} IN ${sharedSubsessionIds}` + ), +]); const subsessionIdToSharedRaceResultsMap = sharedSubsessionRaceResults.reduce( (map: Map>, value) => { const { subsession_id } = value; @@ -93,7 +95,7 @@ const results = sharedSubsessions.map((subsession) => { headToHeadWins[display_name] = [subsession_id]; } const { group_name: License } = Array.isArray(allowed_licenses) - ? allowed_licenses.slice(0, 2).pop() as LicenseType + ? (allowed_licenses.slice(0, 2).pop() as LicenseType) : { group_name: "" }; const assertTrackAsTrackType = () => track as Track; const trackInfo = assertTrackAsTrackType(); diff --git a/src/pages/subsession/[id].astro b/src/pages/subsession/[id].astro index 34e24c5..4f6bd85 100644 --- a/src/pages/subsession/[id].astro +++ b/src/pages/subsession/[id].astro @@ -22,25 +22,28 @@ export async function getStaticPaths() { return subsessions.map(({ subsession_id: id }) => ({ params: { id } })); } const { id } = Astro.params; -const [subsession] = await db - .select() - .from(Subsession) - .where(eq(Subsession.subsession_id, Number(id))); -const practiceResults = await db - .select() - .from(SubsessionPracticeResults) - .where(eq(SubsessionPracticeResults.subsession_id, Number(id))) - .orderBy(asc(SubsessionPracticeResults.finish_position)); -const qualifyingResults = await db - .select() - .from(SubsessionQualifyingResults) - .where(eq(SubsessionQualifyingResults.subsession_id, Number(id))) - .orderBy(asc(SubsessionQualifyingResults.finish_position)); -const raceResults = await db - .select() - .from(SubsessionRaceResults) - .where(eq(SubsessionRaceResults.subsession_id, Number(id))) - .orderBy(asc(SubsessionRaceResults.finish_position)); +const [subsessions, practiceResults, qualifyingResults, raceResults] = await db.batch([ + db + .select() + .from(Subsession) + .where(eq(Subsession.subsession_id, Number(id))), + db + .select() + .from(SubsessionPracticeResults) + .where(eq(SubsessionPracticeResults.subsession_id, Number(id))) + .orderBy(asc(SubsessionPracticeResults.finish_position)), + db + .select() + .from(SubsessionQualifyingResults) + .where(eq(SubsessionQualifyingResults.subsession_id, Number(id))) + .orderBy(asc(SubsessionQualifyingResults.finish_position)), + db + .select() + .from(SubsessionRaceResults) + .where(eq(SubsessionRaceResults.subsession_id, Number(id))) + .orderBy(asc(SubsessionRaceResults.finish_position)), +]); +const subsession = subsessions.pop(); const [practiceResultOne] = practiceResults || [{}]; const [qualifyingResultOne] = qualifyingResults || [{}]; const splitRaceResults = raceResults.find((result) => @@ -108,7 +111,7 @@ const { const title = `Subsession - ${id}`; const description = `Subsession information for subsession - ${id}`; const notMultiClass = - Array.isArray(subsession.car_classes) && subsession.car_classes.length === 1; + Array.isArray(subsession?.car_classes) && subsession?.car_classes.length === 1; --- diff --git a/src/pages/user/[id]/scheduling/by-week/[timestamp].astro b/src/pages/user/[id]/scheduling/by-week/[timestamp].astro index ada02b6..ad53631 100644 --- a/src/pages/user/[id]/scheduling/by-week/[timestamp].astro +++ b/src/pages/user/[id]/scheduling/by-week/[timestamp].astro @@ -19,13 +19,25 @@ export async function getStaticPaths() { .flat(); } const { id, timestamp } = Astro.params; -const [user] = await db +const [users, cars, carClassesResults, carClasses, seasons] = await db.batch([ +db .select({ carPackages: User.car_packages, trackPackages: User.track_packages, }) .from(User) - .where(eq(User.cust_id, id)); + .where(eq(User.cust_id, id)), + db.select().from(Car), + db + .select({ + carClassId: CarClass.car_class_id, + carsInClass: CarClass.cars_in_class, + }) + .from(CarClass), + db.select().from(CarClass), + db.select().from(Season) +]); +const user = users.pop() || { carPackages: [], trackPackages: [] }; const { carPackages, trackPackages } = user; const carIds = Array.isArray(carPackages) ? carPackages.map((carPackage) => carPackage.content_ids).flat() @@ -33,26 +45,18 @@ const carIds = Array.isArray(carPackages) const trackIds = Array.isArray(trackPackages) ? trackPackages.map((trackPackage) => trackPackage.content_ids).flat() : []; -const cars = await db.select().from(Car); const carsMap = new Map(); cars.forEach((car) => { const { car_id } = car; carsMap.set(car_id, car); }); -// @todo Improve this query to not have to do this -const carClassesResults = await db - .select({ - carClassId: CarClass.car_class_id, - carsInClass: CarClass.cars_in_class, - }) - .from(CarClass); +// @todo Improve CarClass query to not have to do this const carClassIdsForCarIds = carClassesResults .filter((result: any) => result.carsInClass.some((v: any) => carIds.includes(v.car_id)) ) .map((result) => result.carClassId); // End comment of previous todo -const carClasses = await db.select().from(CarClass); const carClassesMap = new Map(); carClasses.forEach((carClass) => { const { car_class_id, cars_in_class } = carClass; @@ -70,7 +74,6 @@ const licenseGroupToNameMap: Record = { "4": "Class B", "5": "Class A", }; -const seasons = await db.select().from(Season); const schedulesForWeek = seasons.reduce( (array: Array>, season) => { const { schedules, ...rest } = season; diff --git a/src/pages/user/[id]/scheduling/index.astro b/src/pages/user/[id]/scheduling/index.astro index dee638c..af89ce7 100644 --- a/src/pages/user/[id]/scheduling/index.astro +++ b/src/pages/user/[id]/scheduling/index.astro @@ -7,13 +7,25 @@ export async function getStaticPaths() { return userIds.map(({ id }) => ({ params: { id } })); } const { id } = Astro.params; -const [user] = await db +const [users, cars, carClassesResults, carClasses, seasons] = await db.batch([ +db .select({ carPackages: User.car_packages, trackPackages: User.track_packages, }) .from(User) - .where(eq(User.cust_id, id)); + .where(eq(User.cust_id, id)), + db.select().from(Car), + db + .select({ + carClassId: CarClass.car_class_id, + carsInClass: CarClass.cars_in_class, + }) + .from(CarClass), + db.select().from(CarClass), + db.select().from(Season) +]); +const user = users.pop() || { carPackages: [], trackPackages: [] }; const { carPackages, trackPackages } = user; const carIds = Array.isArray(carPackages) ? carPackages.map((carPackage) => carPackage.content_ids).flat() @@ -21,26 +33,18 @@ const carIds = Array.isArray(carPackages) const trackIds = Array.isArray(trackPackages) ? trackPackages.map((trackPackage) => trackPackage.content_ids).flat() : []; -const cars = await db.select().from(Car); const carsMap = new Map(); cars.forEach((car) => { const { car_id } = car; carsMap.set(car_id, car); }); -// @todo Improve this query to not have to do this -const carClassesResults = await db - .select({ - carClassId: CarClass.car_class_id, - carsInClass: CarClass.cars_in_class, - }) - .from(CarClass); +// @todo Improve CarClass query to not have to do this const carClassIdsForCarIds = carClassesResults .filter((result: any) => result.carsInClass.some((v: any) => carIds.includes(v.car_id)) ) .map((result) => result.carClassId); // End comment of previous todo -const carClasses = await db.select().from(CarClass); const carClassesMap = new Map(); carClasses.forEach((carClass) => { const { car_class_id, cars_in_class } = carClass; @@ -49,7 +53,6 @@ carClasses.forEach((carClass) => { : []; carClassesMap.set(car_class_id, { ...carClass, cars_in_class: carsInClass }); }); -const seasons = await db.select().from(Season); const carClassIdSet = new Set(carClassIdsForCarIds); const trackIdSet = new Set(trackIds); const licenseGroupToNameMap: Record = { diff --git a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro index b4d0b33..86f8fc4 100644 --- a/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro +++ b/src/pages/user/[id]/season/[seasonId]/car-class/[carClassId]/season-summary.astro @@ -35,31 +35,43 @@ export async function getStaticPaths() { })); } const { id, seasonId, carClassId } = Astro.params; -const allSeasonSubsessions = await db - .select() - .from(Subsession) - .innerJoin( - SubsessionRaceResults, - eq(Subsession.subsession_id, SubsessionRaceResults.subsession_id) - ) - .where( - and( - eq(Subsession.season_id, Number(seasonId)), - eq(SubsessionRaceResults.cust_id, Number(id)), - eq(SubsessionRaceResults.car_class_id, Number(carClassId)), - sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE", "N/A"]}` +const [subsessions, seasons, pastSeasonInformations] = await db.batch([ + db + .select() + .from(Subsession) + .innerJoin( + SubsessionRaceResults, + eq(Subsession.subsession_id, SubsessionRaceResults.subsession_id) ) - ); -const subsessions = allSeasonSubsessions; -const [season] = await db - .select() - .from(Standing) - .where(eq(Standing.id, `${seasonId}_${carClassId}_${id}`)); -const [pastSeasonInformation] = await db - .select() - .from(PastSeason) - .where(eq(PastSeason.season_id, Number(seasonId))); -const trackSchedule = Array.isArray(pastSeasonInformation.race_weeks) + .where( + and( + eq(Subsession.season_id, Number(seasonId)), + eq(SubsessionRaceResults.cust_id, Number(id)), + eq(SubsessionRaceResults.car_class_id, Number(carClassId)), + sql`${SubsessionRaceResults.simsession_name} IN ${["RACE", "FEATURE", "N/A"]}` + ) + ), + db + .select() + .from(Standing) + .where(eq(Standing.id, `${seasonId}_${carClassId}_${id}`)), + db + .select() + .from(PastSeason) + .where(eq(PastSeason.season_id, Number(seasonId))), +]); +const season = seasons.pop() || { + division: 0, + division_rank: 0, + overall_rank: 0, + season_name: "", + display_name: "", + points: 0, +}; +const pastSeasonInformation = pastSeasonInformations.pop() || { + race_weeks: [], +}; +const trackSchedule = Array.isArray(pastSeasonInformation?.race_weeks) ? pastSeasonInformation.race_weeks.map((raceWeek: Record) => ({ ...raceWeek.track, race_week_num: raceWeek.race_week_num,