Skip to content

Commit

Permalink
fix: Testing if ufbt deletion step can be sped up
Browse files Browse the repository at this point in the history
  • Loading branch information
Veikkosuhonen committed Jan 28, 2025
1 parent 41cc440 commit 782cfb7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/updater/updateStudentFeedbackTargets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { FeedbackTarget, UserFeedbackTarget } = require('../models')
const logger = require('../util/logger')
const mangleData = require('./mangleData')
const { fetchData } = require('./importerClient')
const { sequelize } = require('../db/dbConnection')

const getEnrolmentFeedbackTargets = async (enrolments) => {
const courseUnitRealisationIds = enrolments.map(({ courseUnitRealisationId }) => courseUnitRealisationId)
Expand Down Expand Up @@ -53,7 +54,9 @@ const deleteInactiveEnrolments = async (enrolments) => {
}))
)

userFeedbackTargetsToDelete.forEach(async (ufbt) => {
const transaction = await sequelize.transaction()

await Promise.all(userFeedbackTargetsToDelete.map(async (ufbt) => {
const deleted = await UserFeedbackTarget.destroy({
where: {
userId: ufbt.userId,
Expand All @@ -63,10 +66,13 @@ const deleteInactiveEnrolments = async (enrolments) => {
feedbackOpenEmailSent: false,
feedbackId: null,
},
transaction,
})

if (deleted) logger.debug('Deleted student feedback target', { userId: ufbt.userId, feedbackTargetId: ufbt.feedbackTargetId })
})
}))

await transaction.commit()
}

const createEnrolmentFallback = async (ufbt) => {
Expand Down

0 comments on commit 782cfb7

Please sign in to comment.