From bba42d59363bd9d897cc42be1625a6d9b9e85b5b Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 3 Dec 2022 15:48:45 +0800 Subject: [PATCH] core: problem_prefix_list: support index by pid --- packages/hydrooj/src/handler/problem.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index ea342332e..620694ce5 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -2,7 +2,7 @@ import AdmZip from 'adm-zip'; import { readFile, statSync } from 'fs-extra'; import { isBinaryFile } from 'isbinaryfile'; import { - escapeRegExp, flattenDeep, intersection, isSafeInteger, pick, + escapeRegExp, flattenDeep, intersection, isSafeInteger, pick, uniqBy, } from 'lodash'; import { FilterQuery, ObjectID } from 'mongodb'; import { nanoid } from 'nanoid'; @@ -997,13 +997,15 @@ export class ProblemPrefixListHandler extends Handler { const pdoc = await problem.get(domainId, +prefix, ['domainId', 'docId', 'pid', 'title']); if (pdoc) pdocs.unshift(pdoc); } + const pdoc = await problem.get(domainId, prefix, ['domainId', 'docId', 'pid', 'title']); + if (pdoc) pdocs.unshift(pdoc); if (pdocs.length < 20) { const search = global.Hydro.lib.problemSearch || defaultSearch; const result = await search(domainId, prefix, { limit: 20 - pdocs.length }); const docs = await problem.getMulti(domainId, { docId: { $in: result.hits.map((i) => +i.split('/')[1]) } }).toArray(); pdocs.push(...docs); } - this.response.body = pdocs; + this.response.body = uniqBy(pdocs, 'docId'); } }