Merge pull request #887 from hydro-dev/remove-union

This commit is contained in:
undefined authored and GitHub committed 2024-10-23 14:18:28 +01:00
commit 965b18d8a6
12 files changed
+88 -108

No files matched your search

+3 -4
View File
@@ -142,10 +142,9 @@ export class ProblemMainHandler extends Handler {
// eslint-disable-next-line prefer-const
let [pdocs, ppcount, pcount] = this.queryContext.fail
? [[], 0, 0]
: await problem.list(
domainId, query, sort.length ? 1 : page, limit,
quick ? ['title', 'pid', 'domainId', 'docId'] : undefined,
this.user._id,
: await this.paginate(
problem.getMulti(domainId, query, quick ? ['title', 'pid', 'domainId', 'docId'] : undefined).sort({ sort: 1, docId: 1 }),
sort.length ? 1 : page, limit,
);
if (total) {
pcount = total;
+8 -11
View File
@@ -358,25 +358,22 @@ class UserDetailHandler extends Handler {
async get(domainId: string, uid: number) {
if (uid === 0) throw new UserNotFoundError(0);
const isSelfProfile = this.user._id === uid;
const [udoc, sdoc, union] = await Promise.all([
const [udoc, sdoc] = await Promise.all([
user.getById(domainId, uid),
token.getMostRecentSessionByUid(uid, ['createAt', 'updateAt']),
domain.get(domainId),
]);
if (!udoc) throw new UserNotFoundError(uid);
const pdocs: ProblemDoc[] = [];
const acInfo: Record<string, number> = {};
const canViewHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id;
if (this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) {
await Promise.all([domainId, ...(union?.union || [])].map(async (did) => {
const psdocs = await problem.getMultiStatus(did, { uid, status: STATUS.STATUS_ACCEPTED }).toArray();
pdocs.push(...Object.values(
await problem.getList(
did, psdocs.map((i) => i.docId), canViewHidden,
false, problem.PROJECTION_LIST, true,
),
));
}));
const psdocs = await problem.getMultiStatus(domainId, { uid, status: STATUS.STATUS_ACCEPTED }).toArray();
pdocs.push(...Object.values(
await problem.getList(
domainId, psdocs.map((i) => i.docId), canViewHidden,
false, problem.PROJECTION_LIST, true,
),
));
}
for (const pdoc of pdocs) {
for (const tag of pdoc.tag) {