From 96f9a138353d978521738f11463641c6b231cc68 Mon Sep 17 00:00:00 2001 From: Dinmukhamed Mailibay <47117969+dinmukhamedm@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:25:46 -0800 Subject: [PATCH] fix evaluations query to write the label to the correct evaluation (#176) --- .../queues/[queueId]/remove/route.ts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/frontend/app/api/projects/[projectId]/queues/[queueId]/remove/route.ts b/frontend/app/api/projects/[projectId]/queues/[queueId]/remove/route.ts index 162efa1b..cbc44d0b 100644 --- a/frontend/app/api/projects/[projectId]/queues/[queueId]/remove/route.ts +++ b/frontend/app/api/projects/[projectId]/queues/[queueId]/remove/route.ts @@ -65,15 +65,20 @@ export async function POST(request: Request, { params }: { params: { projectId: await db.insert(evaluationScores).values(evaluationValues); if (isFeatureEnabled(Feature.FULL_BUILD)) { - const evaluation = await db.query.evaluations.findFirst({ - with: { - evaluationResults: { - where: eq(evaluationResults.id, resultId) - } - } - }); - if (evaluation && evaluationValues.length > 0) { - const result = await clickhouseClient.insert({ + // TODO: optimize this query to use subquery instead of join. + const matchingEvaluations = await db + .select() + .from(evaluations) + .innerJoin(evaluationResults, eq(evaluationResults.evaluationId, evaluations.id)) + .where(and( + eq(evaluationResults.id, resultId), + eq(evaluations.projectId, params.projectId) + )) + .limit(1); + + if (matchingEvaluations.length > 0) { + const evaluation = matchingEvaluations[0].evaluations; + await clickhouseClient.insert({ table: 'evaluation_scores', format: 'JSONEachRow', values: evaluationValues.map(value => ({