core: add limit to problem.getPrefixList

This commit is contained in:
undefined committed 2022-09-20 01:41:53 +08:00
1 parent ca670a2f12
commit 10dd5d28d5
5 files changed
+14 -10

No files matched your search

+5 -7
View File
@@ -990,17 +990,15 @@ export class ProblemPrefixListHandler extends Handler {
@param('prefix', Types.Name)
async get(domainId: string, prefix: string) {
const pdocs = await problem.getPrefixList(domainId, prefix);
if (!Number.isNaN(+prefix)) {
if (!Number.isNaN(+prefix) && !pdocs.filter((i) => i.docId === +prefix)) {
const pdoc = await problem.get(domainId, +prefix, ['domainId', 'docId', 'pid', 'title']);
if (pdoc) pdocs.unshift(pdoc);
}
const search = global.Hydro.lib.problemSearch;
if (pdocs.length < 20) {
if (search) {
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);
}
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;
}