mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core&judge: allow performance mode
This commit is contained in:
1 parent
080621738e
commit
4adf05c50b
5 files changed
+41
-32
No files matched your search
@@ -26,6 +26,7 @@ const JudgeSettings = Schema.object({
|
||||
secret: Schema.string().description('Judge Token Secret').default(String.random(32)),
|
||||
disable: Schema.boolean().description('Disable builtin judge').default(false),
|
||||
detail: Schema.boolean().description('Show diff detail').default(true),
|
||||
performance: Schema.boolean().description('Performance mode').default(false),
|
||||
});
|
||||
|
||||
const oldPath = path.resolve(os.homedir(), '.config', 'hydro', 'judge.yaml');
|
||||
|
||||
@@ -155,13 +155,19 @@ export default class Hydro {
|
||||
getNext(t: JudgeTask) {
|
||||
return (data: Partial<JudgeResultBody>) => {
|
||||
log.debug('Next: %o', data);
|
||||
this.send(t.request.rid, 'next', data);
|
||||
if (getConfig('performance') && data.case && !data.compilerText && !data.message) {
|
||||
t.callbackCache ||= [];
|
||||
t.callbackCache.push(data.case);
|
||||
} else {
|
||||
this.send(t.request.rid, 'next', data);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
getEnd(t: JudgeTask) {
|
||||
return (data: Partial<JudgeResultBody>) => {
|
||||
log.info('End: %o', data);
|
||||
if (t.callbackCache) data.cases = t.callbackCache;
|
||||
this.send(t.request.rid, 'end', data);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from 'fs-extra';
|
||||
import { LangConfig } from '@hydrooj/utils/lib/lang';
|
||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||
import type {
|
||||
FileInfo, JudgeMeta, JudgeRequest, JudgeResultBody,
|
||||
FileInfo, JudgeMeta, JudgeRequest, JudgeResultBody, TestCase,
|
||||
} from 'hydrooj';
|
||||
import readCases from './cases';
|
||||
import { getConfig } from './config';
|
||||
@@ -40,6 +40,7 @@ export class JudgeTask {
|
||||
next: (data: Partial<JudgeResultBody>) => void;
|
||||
end: (data: Partial<JudgeResultBody>) => void;
|
||||
env: Record<string, string>;
|
||||
callbackCache?: TestCase[];
|
||||
|
||||
constructor(public session: Session, public request: JudgeRequest) {
|
||||
this.stat = {};
|
||||
|
||||
@@ -24,20 +24,25 @@ import { sleep } from '../utils';
|
||||
|
||||
const logger = new Logger('judge');
|
||||
|
||||
export async function next(body: Partial<JudgeResultBody>) {
|
||||
body.rid = new ObjectID(body.rid);
|
||||
let rdoc = await record.get(body.rid);
|
||||
if (!rdoc) return;
|
||||
function parseCaseResult(body: TestCase): Required<TestCase> {
|
||||
return {
|
||||
...body,
|
||||
id: body.id || 0,
|
||||
subtaskId: body.subtaskId || 0,
|
||||
score: body.score || 0,
|
||||
message: body.message || '',
|
||||
};
|
||||
}
|
||||
|
||||
function processPayload(rdoc: RecordDoc, body: Partial<JudgeResultBody>) {
|
||||
const $set: Partial<RecordDoc> = {};
|
||||
const $push: any = {};
|
||||
if (body.case) {
|
||||
const c: Required<TestCase> = {
|
||||
...body.case,
|
||||
id: body.case.id || 0,
|
||||
subtaskId: body.case.subtaskId || 0,
|
||||
score: body.case.score || 0,
|
||||
message: body.case.message || '',
|
||||
};
|
||||
if (body.cases?.length) {
|
||||
const c = body.cases.map(parseCaseResult);
|
||||
rdoc.testCases.push(...c);
|
||||
$push.testCases = { $each: c };
|
||||
} else if (body.case) {
|
||||
const c = parseCaseResult(body.case);
|
||||
rdoc.testCases.push(c);
|
||||
$push.testCases = c;
|
||||
}
|
||||
@@ -50,10 +55,18 @@ export async function next(body: Partial<JudgeResultBody>) {
|
||||
$push.compilerTexts = body.compilerText;
|
||||
}
|
||||
if (body.status) $set.status = body.status;
|
||||
if (body.score !== undefined) $set.score = body.score;
|
||||
if (body.time !== undefined) $set.time = body.time;
|
||||
if (body.memory !== undefined) $set.memory = body.memory;
|
||||
if (Number.isFinite(body.score)) $set.score = Math.floor(body.score * 100) / 100;
|
||||
if (Number.isFinite(body.time)) $set.time = body.time;
|
||||
if (Number.isFinite(body.memory)) $set.memory = body.memory;
|
||||
if (body.progress !== undefined) $set.progress = body.progress;
|
||||
return { $set, $push };
|
||||
}
|
||||
|
||||
export async function next(body: Partial<JudgeResultBody>) {
|
||||
body.rid = new ObjectID(body.rid);
|
||||
let rdoc = await record.get(body.rid);
|
||||
if (!rdoc) return;
|
||||
const { $set, $push } = processPayload(rdoc, body);
|
||||
rdoc = await record.update(rdoc.domainId, body.rid, $set, $push, {}, body.addProgress ? { progress: body.addProgress } : {});
|
||||
bus.broadcast('record/change', rdoc!, $set, $push);
|
||||
}
|
||||
@@ -118,21 +131,8 @@ export async function end(body: Partial<JudgeResultBody>) {
|
||||
body.rid &&= new ObjectID(body.rid);
|
||||
let rdoc = await record.get(body.rid);
|
||||
if (!rdoc) return;
|
||||
const $set: Partial<RecordDoc> = {};
|
||||
const $push: any = {};
|
||||
const { $set, $push } = processPayload(rdoc, body);
|
||||
const $unset: any = { progress: '' };
|
||||
if (body.message) {
|
||||
rdoc.judgeTexts.push(body.message);
|
||||
$push.judgeTexts = body.message;
|
||||
}
|
||||
if (body.compilerText) {
|
||||
rdoc.compilerTexts.push(body.compilerText);
|
||||
$push.compilerTexts = body.compilerText;
|
||||
}
|
||||
if (body.status) $set.status = body.status;
|
||||
if (Number.isFinite(body.score)) $set.score = Math.floor(body.score * 100) / 100;
|
||||
if (Number.isFinite(body.time)) $set.time = body.time;
|
||||
if (Number.isFinite(body.memory)) $set.memory = body.memory;
|
||||
$set.judgeAt = new Date();
|
||||
$set.judger = body.judger ?? 1;
|
||||
await sleep(100); // Make sure that all 'next' event already triggered
|
||||
|
||||
@@ -567,7 +567,8 @@ export interface JudgeResultBody {
|
||||
judger?: number;
|
||||
progress?: number;
|
||||
addProgress?: number;
|
||||
case?: TestCase,
|
||||
case?: TestCase;
|
||||
cases?: TestCase[];
|
||||
status?: number;
|
||||
score?: number;
|
||||
/** in miliseconds */
|
||||
|
||||
Reference in new issue
Block a user