mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix problemStat aggr executing
This commit is contained in:
1 parent
be0b90dcd4
commit
139c1e2f59
1 file changed
+38
-33
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
import db from '../service/db';
|
import db from '../service/db';
|
||||||
import { STATUS } from '../model/builtin';
|
import { STATUS } from '../model/builtin';
|
||||||
import * as document from '../model/document';
|
import * as document from '../model/document';
|
||||||
@@ -26,22 +27,24 @@ export async function udoc() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const bulk = db.collection('domain.user').initializeUnorderedBulkOp();
|
let bulk = db.collection('domain.user').initializeUnorderedBulkOp();
|
||||||
db.collection('record').aggregate(pipeline).each(
|
const cursor = db.collection('record').aggregate(pipeline);
|
||||||
(err, adoc: any) => {
|
while (cursor.hasNext()) {
|
||||||
if (adoc) {
|
const adoc = await cursor.next() as any;
|
||||||
bulk.find({
|
bulk.find({
|
||||||
domainId: adoc._id.domainId,
|
domainId: adoc._id.domainId,
|
||||||
uid: adoc._id.uid,
|
uid: adoc._id.uid,
|
||||||
}).updateOne({
|
}).updateOne({
|
||||||
$set: {
|
$set: {
|
||||||
nSubmit: adoc.nSubmit,
|
nSubmit: adoc.nSubmit,
|
||||||
nAccept: adoc.nAccept,
|
nAccept: adoc.nAccept,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
if (bulk.length > 100) {
|
||||||
},
|
await bulk.execute();
|
||||||
);
|
bulk = db.collection('domain.user').initializeUnorderedBulkOp();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (bulk.length) await bulk.execute();
|
if (bulk.length) await bulk.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,23 +70,25 @@ export async function pdoc() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const bulk = db.collection('document').initializeUnorderedBulkOp();
|
let bulk = db.collection('document').initializeUnorderedBulkOp();
|
||||||
db.collection('record').aggregate(pipeline).each(
|
const data = db.collection('record').aggregate(pipeline);
|
||||||
(err, adoc: any) => {
|
while (await data.hasNext()) {
|
||||||
if (adoc) {
|
const adoc = await data.next() as any;
|
||||||
bulk.find({
|
bulk.find({
|
||||||
domainId: adoc._id.domainId,
|
domainId: adoc._id.domainId,
|
||||||
docType: document.TYPE_PROBLEM,
|
docType: document.TYPE_PROBLEM,
|
||||||
docId: adoc._id.pid,
|
docId: adoc._id.pid,
|
||||||
}).updateOne({
|
}).updateOne({
|
||||||
$set: {
|
$set: {
|
||||||
nSubmit: adoc.nSubmit,
|
nSubmit: adoc.nSubmit,
|
||||||
nAccept: adoc.nAccept,
|
nAccept: adoc.nAccept,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
if (bulk.length > 100) {
|
||||||
},
|
await bulk.execute();
|
||||||
);
|
bulk = db.collection('domain.user').initializeUnorderedBulkOp();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (bulk.length) await bulk.execute();
|
if (bulk.length) await bulk.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user