core: fix record stat update

This commit is contained in:
undefined committed 2024-05-29 21:59:53 +08:00
1 parent 8619261bd4
commit a7d6265f97
3 files changed
+11 -27

No files matched your search

+1 -1
View File
@@ -264,7 +264,7 @@ export function apply(ctx: Context) {
]));
ctx.on('domain/delete', (domainId) => RecordModel.coll.deleteMany({ domainId }));
ctx.on('record/judge', async (rdoc, updated) => {
if (rdoc.status === STATUS.STATUS_ACCEPTED && updated && !rdoc.contest) {
if (rdoc.status === STATUS.STATUS_ACCEPTED && updated) {
await RecordModel.collStat.updateOne({
_id: rdoc._id,
}, {
-26
View File
@@ -1,13 +1,10 @@
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 db from '../service/db';
import type { WorkerService } from '../service/worker';
import * as DocumentModel from './document';
import RecordModel from './record';
const logger = new Logger('model/schedule');
@@ -67,29 +64,6 @@ 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
View File
@@ -200,6 +200,16 @@ class ApiService extends Service {
unions[typeName] = unionTypes.join(' | ');
this.rebuild();
}
query(query: string, args: Record<string, any>) {
return graphql({
schema,
source: query,
rootValue: root,
contextValue: this,
variableValues: args,
});
}
}
export const sideEffect = true;