core: move hack to record/judge

This commit is contained in:
undefined committed 2024-04-29 12:47:32 +08:00
1 parent c9c93fd5b3
commit a2ed84a4be
2 files changed
+8 -8

No files matched your search

+7 -7
View File
@@ -98,14 +98,17 @@ export async function postJudge(rdoc: RecordDoc) {
const pdoc = (accept && updated)
? await problem.inc(rdoc.domainId, rdoc.pid, 'nAccept', 1)
: await problem.get(rdoc.domainId, rdoc.pid, undefined, true);
if (pdoc) {
if (isNormalSubmission) {
if (pdoc && isNormalSubmission) {
await Promise.all([
problem.inc(pdoc.domainId, pdoc.docId, `stats.${builtin.STATUS_SHORT_TEXTS[rdoc.status]}`, 1),
problem.inc(pdoc.domainId, pdoc.docId, `stats.s${Math.floor(rdoc.score)}`, 1),
]);
}
if (rdoc.status === STATUS.STATUS_HACK_SUCCESSFUL) {
await bus.parallel('record/judge', rdoc, updated, pdoc);
}
bus.on('record/judge', async (rdoc, updated, pdoc) => {
if (!pdoc || rdoc.status !== STATUS.STATUS_HACK_SUCCESSFUL) return;
try {
const config = yaml.load(pdoc.config as string) as ProblemConfigFile;
assert(config.subtasks instanceof Array);
@@ -135,10 +138,7 @@ export async function postJudge(rdoc: RecordDoc) {
message: { message: 'Unable to apply hack: {0}', params: [e.message] },
});
}
}
}
await bus.parallel('record/judge', rdoc, updated);
}
});
export async function end(body: Partial<JudgeResultBody>) {
body.rid = new ObjectId(body.rid); // TODO remove this
+1 -1
View File
@@ -104,7 +104,7 @@ export interface EventMap extends LifecycleEvents, HandlerEvents {
'training/get': (tdoc: TrainingDoc, handler: any) => VoidReturn
'record/change': (rdoc: RecordDoc, $set?: any, $push?: any, body?: any) => void
'record/judge': (rdoc: RecordDoc, updated: boolean) => VoidReturn
'record/judge': (rdoc: RecordDoc, updated: boolean, pdoc?: ProblemDoc) => VoidReturn
}
/* eslint-enable @typescript-eslint/naming-convention */