Skip to content

Commit

Permalink
Make update slightly more memory efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb committed Mar 24, 2024
1 parent 32d78d3 commit 8ec019c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/tasks/scrape-sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,14 @@ export class ScrapeSectionsTask {
}

await db.serializable(this.pool, async trx => {
// Mark courses and sections in term as deleted by default
// Mark courses in term as deleted by default
await db.update('Course', {
deletedAt: new Date(),
}, {
semester,
year
}).run(trx);

await db.update('Section', {
deletedAt: new Date(),
}, {
courseId: db.sql`${db.self} IN (SELECT ${'id'} FROM ${'Course'} WHERE ${'semester'} = ${db.param(semester)} AND ${'year'} = ${db.param(year)})`
}).run(trx);

// Upsert courses
await db.upsert('Course', extensionCourses.map(extensionCourse => {
const [minCredits, maxCredits] = this.getCreditsRangeFromCourse(extensionCourse);
Expand All @@ -74,6 +68,15 @@ export class ScrapeSectionsTask {
'maxCredits'
])
}).run(trx);
});

await db.serializable(this.pool, async trx => {
// Mark sections in term as deleted by default
await db.update('Section', {
deletedAt: new Date(),
}, {
courseId: db.sql`${db.self} IN (SELECT ${'id'} FROM ${'Course'} WHERE ${'semester'} = ${db.param(semester)} AND ${'year'} = ${db.param(year)})`
}).run(trx);

// Upsert sections
const sectionsUpsertInput: Array<InsertableForTable<'Section'>> = extensionCourses.flatMap(extensionCourse => extensionCourse.sections.map(extensionSection => {
Expand Down

0 comments on commit 8ec019c

Please sign in to comment.