core: fix bulk rejudge

This commit is contained in:
undefined committed 2023-12-16 03:32:14 +08:00
1 parent 0bb348b5b3
commit 18088ed7ed
1 file changed
+12 -10
+12 -10
View File
@@ -72,28 +72,29 @@ export default class RecordModel {
static async judge(domainId: string, rids: MaybeArray<ObjectId>, priority = 0, config: ProblemConfigFile = {}, meta: Partial<JudgeMeta> = {}) {
rids = rids instanceof Array ? rids : [rids];
if (!rids.length) return null;
const rdoc = await RecordModel.get(domainId, rids[0]);
if (!rdoc) return null;
let source = `${domainId}/${rdoc.pid}`;
const rdocs = (await Promise.all(rids.map((rid) => RecordModel.get(domainId, rid)))).filter((i) => i);
if (!rdocs.length) return null;
let source = `${domainId}/${rdocs[0].pid}`;
await task.deleteMany({ rid: { $in: rids } });
let pdoc = await problem.get(rdoc.domainId, rdoc.pid);
if (!pdoc) throw new ProblemNotFoundError(rdoc.domainId, rdoc.pid);
let pdoc = await problem.get(domainId, rdocs[0].pid);
if (!pdoc) throw new ProblemNotFoundError(domainId, rdocs[0].pid);
if (pdoc.reference) {
pdoc = await problem.get(pdoc.reference.domainId, pdoc.reference.pid);
if (!pdoc) throw new ProblemNotFoundError(rdoc.domainId, rdoc.pid);
if (!pdoc) throw new ProblemNotFoundError(domainId, rdocs[0].pid);
source = `${pdoc.domainId}/${pdoc.docId}`;
}
meta = { ...meta, problemOwner: pdoc.owner };
if (typeof pdoc.config === 'string') throw new Error(pdoc.config);
return await task.addMany(rdocs.map((rdoc) => {
let type = 'judge';
if (typeof pdoc.config === 'string') throw new Error(pdoc.config);
if (pdoc.config.type === 'remote_judge' && rdoc.contest?.toHexString() !== '0'.repeat(24)) type = 'remotejudge';
else if (meta?.type === 'generate') type = 'generate';
return await task.addMany(rids.map((rid) => ({
return ({
...(pdoc.config as any), // TODO deprecate this
lang: rdoc.lang,
priority,
type,
rid,
rid: rdoc._id,
domainId,
config: {
...(pdoc.config as any),
@@ -102,7 +103,8 @@ export default class RecordModel {
data: pdoc.data,
source,
meta,
} as any)));
} as any);
}));
}
static async add(