ui: display fix

This commit is contained in:
undefined committed 2024-05-11 04:59:09 +08:00
1 parent 35244cde62
commit 9abd0ef996
6 files changed
+57 -22

No files matched your search

+18 -12
View File
@@ -256,20 +256,26 @@ export default class RecordModel {
export function apply(ctx: Context) {
// Mark problem as deleted
ctx.on('problem/delete', (domainId, docId) => RecordModel.coll.deleteMany({ domainId, pid: docId }));
ctx.on('problem/delete', (domainId, docId) => Promise.all([
RecordModel.coll.deleteMany({ domainId, pid: docId }),
RecordModel.collStat.deleteMany({ domainId, pid: docId }),
]));
ctx.on('domain/delete', (domainId) => RecordModel.coll.deleteMany({ domainId }));
ctx.on('record/judge', (rdoc, updated) => {
if (rdoc.status === STATUS.STATUS_ACCEPTED && updated) {
RecordModel.collStat.insertOne({
ctx.on('record/judge', async (rdoc, updated) => {
if (rdoc.status === STATUS.STATUS_ACCEPTED && updated && !rdoc.contest) {
await RecordModel.collStat.updateOne({
_id: rdoc._id,
domainId: rdoc.domainId,
pid: rdoc.pid,
uid: rdoc.uid,
time: rdoc.time,
memory: rdoc.memory,
length: rdoc.code?.length || 0,
lang: rdoc.lang,
});
}, {
$set: {
domainId: rdoc.domainId,
pid: rdoc.pid,
uid: rdoc.uid,
time: rdoc.time,
memory: rdoc.memory,
length: rdoc.code?.length || 0,
lang: rdoc.lang,
},
}, { upsert: true });
}
});
ctx.on('ready', async () => {
+26
View File
@@ -1,8 +1,11 @@
import moment from 'moment-timezone';
import { Filter, ObjectId } from 'mongodb';
import { Time } from '@hydrooj/utils';
import { STATUS } from '@hydrooj/utils/lib/status';
import { Context } from '../context';
import { Schedule } from '../interface';
import { Logger } from '../logger';
import { ContestModel, DocumentModel } from '../plugin-api';
import db from '../service/db';
import type { WorkerService } from '../service/worker';
import RecordModel from './record';
@@ -64,6 +67,29 @@ export async function apply(ctx: Context) {
ScheduleModel.Worker = c.worker;
c.worker.addHandler('task.daily', async () => {
await RecordModel.coll.deleteMany({ contest: { $in: [RecordModel.RECORD_PRETEST, RecordModel.RECORD_GENERATE] } });
const tdocs = await db.collection('document').find({
docType: DocumentModel.TYPE_CONTEST,
endAt: { $gt: new Date(Date.now() - 2 * Time.day) },
}).project({ docId: 1, beginAt: 1 }).toArray();
const first = Math.min(...tdocs.map((i) => i.beginAt.getTime()));
const bulk = RecordModel.collStat.initializeUnorderedBulkOp();
const cursor = RecordModel.coll.find({
status: STATUS.STATUS_ACCEPTED,
contest: { $in: tdocs.map((i) => i.docId) },
_id: { $gt: Time.getObjectID(new Date(first)) },
});
for await (const rdoc of cursor) {
bulk.find({ _id: rdoc._id }).upsert().updateOne({
domainId: rdoc.domainId,
pid: rdoc.pid,
uid: rdoc.uid,
time: rdoc.time,
memory: rdoc.memory,
length: rdoc.code?.length || 0,
lang: rdoc.lang,
});
}
await bulk.execute();
await global.Hydro.script.rp?.run({}, new Logger('task/rp').debug);
await global.Hydro.script.problemStat?.run({}, new Logger('task/problem').debug);
if (global.Hydro.model.system.get('server.checkUpdate') && !(new Date().getDay() % 3)) {
+10 -8
View File
@@ -650,11 +650,13 @@ const scripts: UpgradeScript[] = [
});
},
async function _88_89() {
const cursor = RecordModel.getMulti(undefined, { status: STATUS.STATUS_ACCEPTED });
let bulk = [];
const cursor = RecordModel.getMulti(undefined, {
status: STATUS.STATUS_ACCEPTED,
contest: { $nin: [RecordModel.RECORD_PRETEST, RecordModel.RECORD_GENERATE] },
});
let bulk = RecordModel.collStat.initializeUnorderedBulkOp();
for await (const doc of cursor) {
bulk.push({
_id: doc._id,
bulk.find({ _id: doc._id }).upsert().updateOne({
domainId: doc.domainId,
pid: doc.pid,
uid: doc.uid,
@@ -663,12 +665,12 @@ const scripts: UpgradeScript[] = [
length: doc.code?.length || 0,
lang: doc.lang,
});
if (bulk.length > 500) {
await RecordModel.collStat.insertMany(bulk);
bulk = [];
if (bulk.batches.length > 500) {
await bulk.execute();
bulk = RecordModel.collStat.initializeUnorderedBulkOp();
}
}
if (bulk.length) await RecordModel.collStat.insertMany(bulk);
if (bulk.batches.length) await bulk.execute();
return true;
},
];