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
+27 -25
+27 -25
View File
@@ -72,37 +72,39 @@ export default class RecordModel {
static async judge(domainId: string, rids: MaybeArray<ObjectId>, priority = 0, config: ProblemConfigFile = {}, meta: Partial<JudgeMeta> = {}) { static async judge(domainId: string, rids: MaybeArray<ObjectId>, priority = 0, config: ProblemConfigFile = {}, meta: Partial<JudgeMeta> = {}) {
rids = rids instanceof Array ? rids : [rids]; rids = rids instanceof Array ? rids : [rids];
if (!rids.length) return null; if (!rids.length) return null;
const rdoc = await RecordModel.get(domainId, rids[0]); const rdocs = (await Promise.all(rids.map((rid) => RecordModel.get(domainId, rid)))).filter((i) => i);
if (!rdoc) return null; if (!rdocs.length) return null;
let source = `${domainId}/${rdoc.pid}`; let source = `${domainId}/${rdocs[0].pid}`;
await task.deleteMany({ rid: { $in: rids } }); await task.deleteMany({ rid: { $in: rids } });
let pdoc = await problem.get(rdoc.domainId, rdoc.pid); let pdoc = await problem.get(domainId, rdocs[0].pid);
if (!pdoc) throw new ProblemNotFoundError(rdoc.domainId, rdoc.pid); if (!pdoc) throw new ProblemNotFoundError(domainId, rdocs[0].pid);
if (pdoc.reference) { if (pdoc.reference) {
pdoc = await problem.get(pdoc.reference.domainId, pdoc.reference.pid); 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}`; source = `${pdoc.domainId}/${pdoc.docId}`;
} }
meta = { ...meta, problemOwner: pdoc.owner }; 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'; let type = 'judge';
if (pdoc.config.type === 'remote_judge' && rdoc.contest?.toHexString() !== '0'.repeat(24)) type = 'remotejudge'; if (typeof pdoc.config === 'string') throw new Error(pdoc.config);
else if (meta?.type === 'generate') type = 'generate'; if (pdoc.config.type === 'remote_judge' && rdoc.contest?.toHexString() !== '0'.repeat(24)) type = 'remotejudge';
return await task.addMany(rids.map((rid) => ({ else if (meta?.type === 'generate') type = 'generate';
...(pdoc.config as any), // TODO deprecate this return ({
lang: rdoc.lang, ...(pdoc.config as any), // TODO deprecate this
priority, lang: rdoc.lang,
type, priority,
rid, type,
domainId, rid: rdoc._id,
config: { domainId,
...(pdoc.config as any), config: {
...config, ...(pdoc.config as any),
}, ...config,
data: pdoc.data, },
source, data: pdoc.data,
meta, source,
} as any))); meta,
} as any);
}));
} }
static async add( static async add(