core: improve daily task performance

This commit is contained in:
undefined committed 2024-10-01 09:09:01 +08:00
1 parent d95eb495ea
commit bccca2f5d2
3 files changed
+17 -24

No files matched your search

-1
View File
@@ -506,7 +506,6 @@ export class ProblemSubmitHandler extends ProblemDetailHandler {
if (!pretest) {
await Promise.all([
problem.inc(domainId, this.pdoc.docId, 'nSubmit', 1),
problem.incStatus(domainId, this.pdoc.docId, this.user._id, 'nSubmit', 1),
domain.incUserInDomain(domainId, this.user._id, 'nSubmit'),
tid && contest.updateStatus(domainId, tid, this.user._id, rid, this.pdoc.docId),
]);
-2
View File
@@ -294,8 +294,6 @@ export interface ProblemStatusDoc extends StatusDocBase {
rid?: ObjectId;
score?: number;
status?: number;
nSubmit?: number;
nAccept?: number;
star?: boolean;
}
+17 -21
View File
@@ -10,7 +10,13 @@ const sumStatus = (status) => ({ $sum: { $cond: [{ $eq: ['$status', status] }, 1
export async function udoc(report) {
report({ message: 'Udoc' });
const pipeline = [
{ $match: { contest: { $nin: [RecordModel.RECORD_PRETEST, RecordModel.RECORD_GENERATE] } } },
{
$match: {
contest: { $nin: [RecordModel.RECORD_PRETEST, RecordModel.RECORD_GENERATE] },
status: { $ne: STATUS.STATUS_CANCELED },
uid: { $gte: 0 },
},
},
{
$group: {
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
@@ -46,23 +52,6 @@ export async function udoc(report) {
if (bulk.batches.length) await bulk.execute();
}
export async function psdoc(report) {
report({ message: 'Psdoc' });
const pipeline = [
{ $match: { contest: { $nin: [RecordModel.RECORD_PRETEST, RecordModel.RECORD_GENERATE] } } },
{
$group: {
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
nSubmit: { $sum: 1 },
},
},
];
const data = db.collection('record').aggregate<any>(pipeline, { allowDiskUse: true });
for await (const adoc of data) {
await document.setStatus(adoc._id.domainId, document.TYPE_PROBLEM, adoc._id.pid, adoc._id.uid, { nSubmit: adoc.nSubmit });
}
}
export async function pdoc(report) {
report({ message: 'Pdoc' });
const pipeline = [
@@ -157,9 +146,16 @@ export const apply = (ctx) => ctx.addScript(
psdoc: Schema.boolean(),
}),
async (arg, report) => {
if (arg.pdoc === undefined || arg.pdoc) await pdoc(report);
if (arg.udoc === undefined || arg.udoc) await udoc(report);
if (arg.psdoc === undefined || arg.psdoc) await psdoc(report);
if (arg.pdoc === undefined || arg.pdoc) {
const start = Date.now();
await pdoc(report);
report({ message: `pdoc finished in ${Date.now() - start}ms` });
}
if (arg.udoc === undefined || arg.udoc) {
const start = Date.now();
await udoc(report);
report({ message: `udoc finished in ${Date.now() - start}ms` });
}
return true;
},
);