Skip to content

Commit

Permalink
Merge pull request #42 from Shinsina/integration-improvements
Browse files Browse the repository at this point in the history
Integration improvements and other corrections
  • Loading branch information
Shinsina authored Apr 18, 2024
2 parents f2dcc48 + c4d9982 commit 6c99b38
Show file tree
Hide file tree
Showing 21 changed files with 196 additions and 210 deletions.
9 changes: 8 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import prefetch from "@astrojs/prefetch";
import alpinejs from "@astrojs/alpinejs";
import sitemap from "@astrojs/sitemap";
import db from "@astrojs/db";

// https://astro.build/config
export default defineConfig({
site: "https://shinsina.github.io",
base: "/Stat-N-Track",
integrations: [tailwind(), prefetch(), sitemap(), db()],
integrations: [
tailwind(),
prefetch(),
alpinejs({ entrypoint: "/src/lib/alpine" }),
sitemap(),
db(),
],
});
38 changes: 21 additions & 17 deletions db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ async function paginatedQuery(
const size = 100;
const count = await collection.countDocuments({});
const batches = Math.ceil(count / size);
const results = await Promise.all(Array(batches)
.fill({})
.map((_, index) => {
console.log(`Processing batch ${index + 1} of ${batches} for ${collection.collectionName}...`)
return collection
.find({})
.skip(index * size)
.limit(size)
.toArray()
}
));
const results = await Promise.all(
Array(batches)
.fill({})
.map((_, index) => {
console.log(
`Processing batch ${index + 1} of ${batches} for ${
collection.collectionName
}...`
);
return collection
.find({})
.skip(index * size)
.limit(size)
.toArray();
})
);
return results.flat();
}

Expand Down Expand Up @@ -122,15 +127,18 @@ export default async function seed() {
console.log("Past Seasons Seeded!");
const subsessionsCollection = mongoDb.collection("subsessions");
// @ts-ignore
const subsessions: Array<SubsessionType> = await paginatedQuery(subsessionsCollection);
const subsessions: Array<SubsessionType> = await paginatedQuery(
subsessionsCollection
);
console.log("Seeding Subsessions...");
const {
allPracticeResults,
allQualifyingResults,
allRaceResults,
allSubsessions,
} = subsessions.reduce(
(object, subsession) => {
// @todo Provide an accurate type for the unknown here
(object: Record<string, Array<any>>, subsession) => {
const { _id, session_results, end_time, start_time, ...rest } =
subsession;
session_results.forEach((sessionResult) => {
Expand All @@ -142,18 +150,14 @@ export default async function seed() {
...rest,
};
if (rest.simsession_type_name.match("Practice")) {
// @ts-ignore
object.allPracticeResults.push(resultWithSession);
} else if (rest.simsession_type_name.match("Qualifying")) {
// @ts-ignore
object.allQualifyingResults.push(resultWithSession);
} else if (rest.simsession_type_name.match("Race")) {
// @ts-ignore
object.allRaceResults.push(resultWithSession);
}
});
});
// @ts-ignore
object.allSubsessions.push({
...rest,
end_time: new Date(end_time),
Expand Down
162 changes: 86 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6c99b38

Please sign in to comment.