mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: problem_prefix_list: support index by pid
This commit is contained in:
1 parent
d92f3f3ed6
commit
bba42d5936
1 file changed
+4
-2
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user