mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: improve daily task performance
This commit is contained in:
3 files changed
+17
-24
No files matched your search
@@ -506,7 +506,6 @@ export class ProblemSubmitHandler extends ProblemDetailHandler {
|
|||||||
if (!pretest) {
|
if (!pretest) {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
problem.inc(domainId, this.pdoc.docId, 'nSubmit', 1),
|
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'),
|
domain.incUserInDomain(domainId, this.user._id, 'nSubmit'),
|
||||||
tid && contest.updateStatus(domainId, tid, this.user._id, rid, this.pdoc.docId),
|
tid && contest.updateStatus(domainId, tid, this.user._id, rid, this.pdoc.docId),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -294,8 +294,6 @@ export interface ProblemStatusDoc extends StatusDocBase {
|
|||||||
rid?: ObjectId;
|
rid?: ObjectId;
|
||||||
score?: number;
|
score?: number;
|
||||||
status?: number;
|
status?: number;
|
||||||
nSubmit?: number;
|
|
||||||
nAccept?: number;
|
|
||||||
star?: boolean;
|
star?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,13 @@ const sumStatus = (status) => ({ $sum: { $cond: [{ $eq: ['$status', status] }, 1
|
|||||||
export async function udoc(report) {
|
export async function udoc(report) {
|
||||||
report({ message: 'Udoc' });
|
report({ message: 'Udoc' });
|
||||||
const pipeline = [
|
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: {
|
$group: {
|
||||||
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||||||
@@ -46,23 +52,6 @@ export async function udoc(report) {
|
|||||||
if (bulk.batches.length) await bulk.execute();
|
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) {
|
export async function pdoc(report) {
|
||||||
report({ message: 'Pdoc' });
|
report({ message: 'Pdoc' });
|
||||||
const pipeline = [
|
const pipeline = [
|
||||||
@@ -157,9 +146,16 @@ export const apply = (ctx) => ctx.addScript(
|
|||||||
psdoc: Schema.boolean(),
|
psdoc: Schema.boolean(),
|
||||||
}),
|
}),
|
||||||
async (arg, report) => {
|
async (arg, report) => {
|
||||||
if (arg.pdoc === undefined || arg.pdoc) await pdoc(report);
|
if (arg.pdoc === undefined || arg.pdoc) {
|
||||||
if (arg.udoc === undefined || arg.udoc) await udoc(report);
|
const start = Date.now();
|
||||||
if (arg.psdoc === undefined || arg.psdoc) await psdoc(report);
|
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;
|
return true;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Reference in new issue
Block a user