mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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 { readFile, statSync } from 'fs-extra';
|
||||||
import { isBinaryFile } from 'isbinaryfile';
|
import { isBinaryFile } from 'isbinaryfile';
|
||||||
import {
|
import {
|
||||||
escapeRegExp, flattenDeep, intersection, isSafeInteger, pick,
|
escapeRegExp, flattenDeep, intersection, isSafeInteger, pick, uniqBy,
|
||||||
} from 'lodash';
|
} from 'lodash';
|
||||||
import { FilterQuery, ObjectID } from 'mongodb';
|
import { FilterQuery, ObjectID } from 'mongodb';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
@@ -997,13 +997,15 @@ export class ProblemPrefixListHandler extends Handler {
|
|||||||
const pdoc = await problem.get(domainId, +prefix, ['domainId', 'docId', 'pid', 'title']);
|
const pdoc = await problem.get(domainId, +prefix, ['domainId', 'docId', 'pid', 'title']);
|
||||||
if (pdoc) pdocs.unshift(pdoc);
|
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) {
|
if (pdocs.length < 20) {
|
||||||
const search = global.Hydro.lib.problemSearch || defaultSearch;
|
const search = global.Hydro.lib.problemSearch || defaultSearch;
|
||||||
const result = await search(domainId, prefix, { limit: 20 - pdocs.length });
|
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();
|
const docs = await problem.getMulti(domainId, { docId: { $in: result.hits.map((i) => +i.split('/')[1]) } }).toArray();
|
||||||
pdocs.push(...docs);
|
pdocs.push(...docs);
|
||||||
}
|
}
|
||||||
this.response.body = pdocs;
|
this.response.body = uniqBy(pdocs, 'docId');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user