core: fix problem_main status cross-domain get

This commit is contained in:
undefined committed 2021-12-21 21:01:29 +08:00
1 parent 40c90c0574
commit 92c1a41585
5 files changed
+16 -8

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.2.26",
"version": "3.2.27",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+8 -3
View File
@@ -125,7 +125,7 @@ export class ProblemMainHandler extends ProblemHandler {
this.response.template = 'problem_main.html';
// eslint-disable-next-line @typescript-eslint/no-shadow
const query: FilterQuery<ProblemDoc> = {};
let psdict = {};
const psdict = {};
const search = global.Hydro.lib.problemSearch;
let sort: string[];
let fail = false;
@@ -168,8 +168,13 @@ export class ProblemMainHandler extends ProblemHandler {
}
}
if (this.user.hasPriv(PRIV.PRIV_USER_PROFILE)) {
psdict = await problem.getListStatus(
domainId, this.user._id, pdocs.map((pdoc) => pdoc.docId),
const domainIds = Array.from(new Set(pdocs.map((i) => i.domainId)));
await Promise.all(
domainIds.map((did) =>
problem.getListStatus(
did, this.user._id,
pdocs.filter((i) => i.domainId === did).map((i) => i.docId),
).then((res) => Object.assign(psdict, res))),
);
}
this.response.body = {
+4 -1
View File
@@ -316,7 +316,10 @@ export class ProblemModel {
domainId, { uid, docId: { $in: Array.from(new Set(pids)) } },
).toArray();
const r: Record<string, ProblemStatusDoc> = {};
for (const psdoc of psdocs) r[psdoc.docId] = psdoc;
for (const psdoc of psdocs) {
r[psdoc.docId] = psdoc;
r[`${psdoc.domainId}#${psdoc.docId}`] = psdoc;
}
return r;
}