Skip to content

Commit

Permalink
Batch subsessions and reduce batch sizes for seeding database
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinsina committed Jun 4, 2024
1 parent bcce0aa commit 16e4f39
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import seasonIdArray from "./distinct-season-ids.json";
import subsessions from "./subsessions-output.json";

function batchInserts(array: Array<any>): Array<Array<any>> {
const size = 200;
const size = 100;
const count = array.length;
const batches = Math.ceil(count / size);
return Array(batches)
Expand Down Expand Up @@ -168,6 +168,11 @@ export default async function seed() {
);
if (subsessionCount !== allSubsessions.length) {
await db.delete(Subsession);
await Promise.all(
batchInserts(allSubsessions).map((batch) =>
db.insert(Subsession).values(batch)
)
);
await db.insert(Subsession).values(allSubsessions);
}
console.log("Seeding Subsession Practice Results...");
Expand Down

0 comments on commit 16e4f39

Please sign in to comment.