Skip to content

Commit

Permalink
fix: attempt to fix duplicate score creation in Intra
Browse files Browse the repository at this point in the history
  • Loading branch information
FreekBes authored Jan 28, 2025
1 parent 32f9841 commit a4673d2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/handlers/intrascores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@ const createIntraScore = async function(prisma: PrismaClient, api: Fast42, score
// updated_at: new Date(postBody.updated_at),
// },
// });
// Check if a score was created in the meantime due to multithreading
const currentIntraScoreId = await prisma.codamCoalitionScore.findFirst({
where: {
id: score.id,
},
select: {
intra_score_id: true,
},
});
if (currentIntraScoreId.intra_score_id != null) {
console.warn(`Two Intra scores were simultaneously created (probably due to multithreading) for score ${score.id}. Deleting duplicate Intra score ${postBody.id}...`);
const del = await api.delete(`/coalitions/${score.coalition_id}/scores/${postBody.id}`, {});
if (!del.ok) {
throw new Error(`Failed to delete duplicate Intra score ${postBody.id}`);
}
return currentIntraScoreId.intra_score_id; // Return with the previously created Intra score
}
await prisma.codamCoalitionScore.update({
where: {
id: score.id,
Expand Down

0 comments on commit a4673d2

Please sign in to comment.