mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 01:36:08 +08:00
core: improve daily task performance
This commit is contained in:
3 files changed
+17
-24
No files matched your search
@@ -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;
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user