Skip to content

Commit

Permalink
ui: display fix
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined-moe committed May 10, 2024
1 parent 35244cd commit 9abd0ef
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"files.eol": "\n",
"editor.detectIndentation": true,
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.tsserver.maxTsServerMemory": 16384,
"[json]": {
"files.insertFinalNewline": true,
"files.trimFinalNewlines": false
Expand Down
30 changes: 18 additions & 12 deletions packages/hydrooj/src/model/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
26 changes: 26 additions & 0 deletions packages/hydrooj/src/model/schedule.ts
Original file line number Diff line number Diff line change
@@ -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';

Check warning on line 8 in packages/hydrooj/src/model/schedule.ts

View workflow job for this annotation

GitHub Actions / build

'ContestModel' is defined but never used
import db from '../service/db';
import type { WorkerService } from '../service/worker';
import RecordModel from './record';
Expand Down Expand Up @@ -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)) {
Expand Down
18 changes: 10 additions & 8 deletions packages/hydrooj/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
},
];
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-default/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.50.0",
"version": "4.50.1",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-default/templates/problem_statistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h1 class="section__title">{{ _('Submission Statistics') }}</h1>
<td class="col--time">{% if rsdoc['time'] %}{% if [STATUS.STATUS_TIME_LIMIT_EXCEEDED, STATUS.STATUS_MEMORY_LIMIT_EXCEEDED, STATUS.STATUS_OUTPUT_LIMIT_EXCEEDED].includes(rsdoc['status']) %}&ge;{% endif %}{{ rsdoc.time|round|int }}ms{% else %}-{% endif %}</td>
<td class="col--memory">{% if rsdoc['memory'] %}{% if [STATUS.STATUS_TIME_LIMIT_EXCEEDED, STATUS.STATUS_MEMORY_LIMIT_EXCEEDED, STATUS.STATUS_OUTPUT_LIMIT_EXCEEDED].includes(rsdoc['status']) %}&ge;{% endif %}{{ size(rsdoc.memory, 1024) }}{% else %}-{% endif %}</td>
<td class="col--lang">{{ model.setting.langs[rsdoc['lang']].display }}</td>
<td class="col--code">{{ size(rsdoc.code) }}</td>
<td class="col--code">{{ size(rsdoc.length) }}</td>
<td class="col--submit-at">{{ datetimeSpan(rsdoc['_id'], false)|safe }}</td>
</tr>
{%- endfor -%}
Expand Down

0 comments on commit 9abd0ef

Please sign in to comment.