mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: fix record stat update
This commit is contained in:
3 files changed
+11
-27
No files matched your search
@@ -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,
|
||||
}, {
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user