Skip to content

Commit a4673d2

Browse files
authored
fix: attempt to fix duplicate score creation in Intra
1 parent 32f9841 commit a4673d2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/handlers/intrascores.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ const createIntraScore = async function(prisma: PrismaClient, api: Fast42, score
9797
// updated_at: new Date(postBody.updated_at),
9898
// },
9999
// });
100+
// Check if a score was created in the meantime due to multithreading
101+
const currentIntraScoreId = await prisma.codamCoalitionScore.findFirst({
102+
where: {
103+
id: score.id,
104+
},
105+
select: {
106+
intra_score_id: true,
107+
},
108+
});
109+
if (currentIntraScoreId.intra_score_id != null) {
110+
console.warn(`Two Intra scores were simultaneously created (probably due to multithreading) for score ${score.id}. Deleting duplicate Intra score ${postBody.id}...`);
111+
const del = await api.delete(`/coalitions/${score.coalition_id}/scores/${postBody.id}`, {});
112+
if (!del.ok) {
113+
throw new Error(`Failed to delete duplicate Intra score ${postBody.id}`);
114+
}
115+
return currentIntraScoreId.intra_score_id; // Return with the previously created Intra score
116+
}
100117
await prisma.codamCoalitionScore.update({
101118
where: {
102119
id: score.id,

0 commit comments

Comments
 (0)