mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: problemStat: also calc psdoc
This commit is contained in:
1 parent
cc1faba709
commit
8a114abb55
4 files changed
+28
-3
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.21.18",
|
||||
"version": "2.21.19",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -240,6 +240,7 @@ export class ProblemSubmitHandler extends ProblemDetailHandler {
|
||||
const [rdoc] = await Promise.all([
|
||||
record.get(domainId, rid),
|
||||
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'),
|
||||
]);
|
||||
bus.boardcast('record/change', rdoc);
|
||||
|
||||
@@ -223,6 +223,13 @@ export class ProblemModel {
|
||||
return !!res;
|
||||
}
|
||||
|
||||
static async incStatus(
|
||||
domainId: string, pid: number, uid: number,
|
||||
key: NumberKeys<ProblemStatusDoc>, count: number,
|
||||
) {
|
||||
return await document.incStatus(domainId, document.TYPE_PROBLEM, pid, uid, key, count);
|
||||
}
|
||||
|
||||
static setStar(domainId: string, pid: number, uid: number, star: boolean) {
|
||||
return document.setStatus(domainId, document.TYPE_PROBLEM, pid, uid, { star });
|
||||
}
|
||||
|
||||
@@ -48,9 +48,26 @@ export async function udoc() {
|
||||
if (bulk.length) await bulk.execute();
|
||||
}
|
||||
|
||||
export async function psdoc() {
|
||||
const pipeline = [
|
||||
{ $match: { hidden: false, type: { $ne: 'run' } } },
|
||||
{
|
||||
$group: {
|
||||
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||||
nSubmit: { $sum: 1 },
|
||||
},
|
||||
},
|
||||
];
|
||||
const data = db.collection('record').aggregate(pipeline);
|
||||
while (await data.hasNext()) {
|
||||
const adoc = await data.next() as any;
|
||||
await document.setStatus(adoc._id.domainId, document.TYPE_PROBLEM, adoc._id.pid, adoc._id.uid, { nSubmit: adoc.nSubmit });
|
||||
}
|
||||
}
|
||||
|
||||
export async function pdoc() {
|
||||
const pipeline = [
|
||||
{ $match: { hidden: false, type: { $ne: 'run' } }, effective: true },
|
||||
{ $match: { hidden: false, type: { $ne: 'run' }, effective: true } },
|
||||
{
|
||||
$group: {
|
||||
_id: { domainId: '$domainId', pid: '$pid', uid: '$uid' },
|
||||
@@ -93,7 +110,7 @@ export async function pdoc() {
|
||||
}
|
||||
|
||||
export async function run() {
|
||||
return await Promise.all([udoc(), pdoc()]);
|
||||
return await Promise.all([udoc(), pdoc(), psdoc()]);
|
||||
}
|
||||
|
||||
export const validate = {};
|
||||
|
||||
Reference in new issue
Block a user