From 38a92d8be8f9af579459ab05b3c920ef215a244b Mon Sep 17 00:00:00 2001 From: Menci Date: Sun, 9 Dec 2018 22:18:08 +0800 Subject: [PATCH] Add testcase result cache --- src/daemon/judge/judger-base.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/daemon/judge/judger-base.ts b/src/daemon/judge/judger-base.ts index 55035a2..727c250 100644 --- a/src/daemon/judge/judger-base.ts +++ b/src/daemon/judge/judger-base.ts @@ -48,6 +48,18 @@ export abstract class JudgerBase { } } + const testcaseDetailsCache: Map = new Map(); + const judgeTestcaseWrapper = async (curCase: TestcaseJudge, started: () => Promise): Promise => { + if (testcaseDetailsCache.has(curCase.name)) { + return testcaseDetailsCache.get(curCase.name); + } + + const result: TestcaseDetails = await this.judgeTestcase(curCase, started); + testcaseDetailsCache.set(curCase.name, result); + + return result; + } + for (let subtaskIndex = 0; subtaskIndex < this.testData.subtasks.length; subtaskIndex++) { const currentResult = results[subtaskIndex]; const currentTask = this.testData.subtasks[subtaskIndex]; @@ -78,7 +90,7 @@ export abstract class JudgerBase { winston.verbose(`Judging ${subtaskIndex}, case ${index}.`); let score = 0; try { - const taskJudge = await this.judgeTestcase(currentTask.cases[index], async () => { + const taskJudge = await judgeTestcaseWrapper(currentTask.cases[index], async () => { currentTaskResult.status = TaskStatus.Running; await reportProgress(); }); @@ -106,7 +118,7 @@ export abstract class JudgerBase { const currentTaskResult = currentResult.cases[index]; winston.verbose(`Judging ${subtaskIndex}, case ${index}.`); try { - currentTaskResult.result = await this.judgeTestcase(currentTask.cases[index], async () => { + currentTaskResult.result = await judgeTestcaseWrapper(currentTask.cases[index], async () => { currentTaskResult.status = TaskStatus.Running; await reportProgress(); });