core: store record rejudge history

This commit is contained in:
undefined committed 2025-03-16 23:10:52 +00:00
1 parent 415d1f4ef1
commit 0e7320fed4
3 files changed
+35 -13

No files matched your search

+12 -9
View File
@@ -81,24 +81,28 @@ export interface JudgeMeta {
type?: string; type?: string;
} }
export interface RecordPayload { export interface RecordJudgeInfo {
domainId: string;
pid: number;
uid: number;
lang: string;
code: string;
score: number; score: number;
memory: number; memory: number;
time: number; time: number;
judgeTexts: (string | JudgeMessage)[]; judgeTexts: (string | JudgeMessage)[];
compilerTexts: string[]; compilerTexts: string[];
testCases: Required<TestCase>[]; testCases: Required<TestCase>[];
rejudged: boolean;
source?: string;
/** judge uid */ /** judge uid */
judger: number; judger: number;
judgeAt: Date; judgeAt: Date;
status: number; status: number;
subtasks?: Record<number, SubtaskResult>;
}
export interface RecordPayload extends RecordJudgeInfo {
domainId: string;
pid: number;
uid: number;
lang: string;
code: string;
rejudged: boolean;
source?: string;
progress?: number; progress?: number;
/** pretest */ /** pretest */
input?: string; input?: string;
@@ -108,7 +112,6 @@ export interface RecordPayload {
contest?: string; contest?: string;
files?: Record<string, string> files?: Record<string, string>
subtasks?: Record<number, SubtaskResult>;
} }
export interface JudgeRequest extends Omit<RecordPayload, 'testCases'> { export interface JudgeRequest extends Omit<RecordPayload, 'testCases'> {
+7 -1
View File
@@ -4,7 +4,7 @@ import type fs from 'fs';
import type { Dictionary, NumericDictionary } from 'lodash'; import type { Dictionary, NumericDictionary } from 'lodash';
import type { Binary, FindCursor, ObjectId } from 'mongodb'; import type { Binary, FindCursor, ObjectId } from 'mongodb';
import type { import type {
FileInfo, RecordPayload, FileInfo, RecordJudgeInfo, RecordPayload,
} from '@hydrooj/common/types'; } from '@hydrooj/common/types';
import type { Context } from './context'; import type { Context } from './context';
import type { DocStatusType } from './model/document'; import type { DocStatusType } from './model/document';
@@ -224,6 +224,11 @@ export type RecordDoc = {
_id: ObjectId; _id: ObjectId;
}; };
export interface RecordHistoryDoc extends RecordJudgeInfo {
_id: ObjectId;
rid: ObjectId;
}
export interface RecordStatDoc { export interface RecordStatDoc {
_id: ObjectId; _id: ObjectId;
domainId: string; domainId: string;
@@ -545,6 +550,7 @@ declare module './service/db' {
'domain.user': any; 'domain.user': any;
'record': RecordDoc; 'record': RecordDoc;
'record.stat': RecordStatDoc; 'record.stat': RecordStatDoc;
'record.history': RecordHistoryDoc;
'document': any; 'document': any;
'document.status': StatusDocBase & { 'document.status': StatusDocBase & {
[K in keyof DocStatusType]: { docType: K } & DocStatusType[K]; [K in keyof DocStatusType]: { docType: K } & DocStatusType[K];
+16 -3
View File
@@ -1,5 +1,5 @@
/* eslint-disable object-curly-newline */ /* eslint-disable object-curly-newline */
import { sum } from 'lodash'; import { pick, sum } from 'lodash';
import moment from 'moment-timezone'; import moment from 'moment-timezone';
import { import {
Filter, FindOptions, MatchKeysAndValues, Filter, FindOptions, MatchKeysAndValues,
@@ -20,6 +20,7 @@ import task from './task';
export default class RecordModel { export default class RecordModel {
static coll = db.collection('record'); static coll = db.collection('record');
static collStat = db.collection('record.stat'); static collStat = db.collection('record.stat');
static collHistory = db.collection('record.history');
static PROJECTION_LIST: (keyof RecordDoc)[] = [ static PROJECTION_LIST: (keyof RecordDoc)[] = [
'_id', 'score', 'time', 'memory', 'lang', '_id', 'score', 'time', 'memory', 'lang',
'uid', 'pid', 'rejudged', 'progress', 'domainId', 'uid', 'pid', 'rejudged', 'progress', 'domainId',
@@ -233,6 +234,7 @@ export default class RecordModel {
} }
static async reset(domainId: string, rid: MaybeArray<ObjectId>, isRejudge: boolean) { static async reset(domainId: string, rid: MaybeArray<ObjectId>, isRejudge: boolean) {
const rids = rid instanceof Array ? rid : [rid];
const upd: any = { const upd: any = {
score: 0, score: 0,
status: STATUS.STATUS_WAITING, status: STATUS.STATUS_WAITING,
@@ -246,8 +248,19 @@ export default class RecordModel {
judger: null, judger: null,
}; };
if (isRejudge) upd.rejudged = true; if (isRejudge) upd.rejudged = true;
await RecordModel.collStat.deleteMany(rid instanceof Array ? { _id: { $in: rid } } : { _id: rid }); const [rdocs] = await Promise.all([
await task.deleteMany(rid instanceof Array ? { rid: { $in: rid } } : { rid }); RecordModel.coll.find({ _id: { $in: rids } }).toArray(),
RecordModel.collStat.deleteMany({ _id: { $in: rids } }),
task.deleteMany({ rid: { $in: rids } }),
]);
await RecordModel.collHistory.insertMany(rdocs.map((rdoc) => ({
...pick(rdoc, [
'compilerTexts', 'judgeTexts', 'testCases', 'subtasks',
'score', 'time', 'memory', 'status', 'judgeAt', 'judger',
]),
rid: rdoc._id,
_id: new ObjectId(),
})));
return RecordModel.update(domainId, rid, upd); return RecordModel.update(domainId, rid, upd);
} }