mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: add limit to problem.getPrefixList
This commit is contained in:
1 parent
ca670a2f12
commit
10dd5d28d5
5 files changed
+14
-10
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user