mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +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;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export async function load() {
|
||||
addon(path.resolve(__dirname, '..'), true);
|
||||
Error.stackTraceLimit = 50;
|
||||
require('./entry/worker').load();
|
||||
if (global.gc) global.gc();
|
||||
global.gc?.();
|
||||
}
|
||||
|
||||
export async function loadCli() {
|
||||
|
||||
@@ -340,7 +340,8 @@ export class ProblemModel {
|
||||
prefix = prefix.toLowerCase();
|
||||
const $regex = new RegExp(`\\A${escapeRegExp(prefix)}`, 'gmi');
|
||||
const filter = { $or: [{ pid: { $regex } }, { title: { $regex } }] };
|
||||
return await document.getMulti(domainId, document.TYPE_PROBLEM, filter, ['domainId', 'docId', 'pid', 'title']).toArray();
|
||||
return await document.getMulti(domainId, document.TYPE_PROBLEM, filter, ['domainId', 'docId', 'pid', 'title'])
|
||||
.limit(20).toArray();
|
||||
}
|
||||
|
||||
static async getListStatus(domainId: string, uid: number, pids: number[]) {
|
||||
|
||||
@@ -33,7 +33,7 @@ async function executeCommand(input: string) {
|
||||
}
|
||||
|
||||
process.stdin.setEncoding('utf-8');
|
||||
if (process.stdin.setRawMode) process.stdin.setRawMode(false);
|
||||
process.stdin.setRawMode?.(false);
|
||||
process.stdin.on('data', (buf) => {
|
||||
const input = buf.toString();
|
||||
executeCommand(input);
|
||||
|
||||
@@ -842,6 +842,11 @@ const scripts: UpgradeScript[] = [
|
||||
}
|
||||
return true;
|
||||
},
|
||||
async function _68_69() {
|
||||
const _FRESH_INSTALL_IGNORE = 1;
|
||||
await db.collection('cache' as any).deleteMany({});
|
||||
return true;
|
||||
},
|
||||
];
|
||||
|
||||
export default scripts;
|
||||
Reference in new issue
Block a user