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
+11
-7
No files matched your search
@@ -990,18 +990,16 @@ export class ProblemPrefixListHandler extends Handler {
|
|||||||
@param('prefix', Types.Name)
|
@param('prefix', Types.Name)
|
||||||
async get(domainId: string, prefix: string) {
|
async get(domainId: string, prefix: string) {
|
||||||
const pdocs = await problem.getPrefixList(domainId, prefix);
|
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']);
|
const pdoc = await problem.get(domainId, +prefix, ['domainId', 'docId', 'pid', 'title']);
|
||||||
if (pdoc) pdocs.unshift(pdoc);
|
if (pdoc) pdocs.unshift(pdoc);
|
||||||
}
|
}
|
||||||
const search = global.Hydro.lib.problemSearch;
|
|
||||||
if (pdocs.length < 20) {
|
if (pdocs.length < 20) {
|
||||||
if (search) {
|
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 = pdocs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ export async function load() {
|
|||||||
addon(path.resolve(__dirname, '..'), true);
|
addon(path.resolve(__dirname, '..'), true);
|
||||||
Error.stackTraceLimit = 50;
|
Error.stackTraceLimit = 50;
|
||||||
require('./entry/worker').load();
|
require('./entry/worker').load();
|
||||||
if (global.gc) global.gc();
|
global.gc?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadCli() {
|
export async function loadCli() {
|
||||||
|
|||||||
@@ -340,7 +340,8 @@ export class ProblemModel {
|
|||||||
prefix = prefix.toLowerCase();
|
prefix = prefix.toLowerCase();
|
||||||
const $regex = new RegExp(`\\A${escapeRegExp(prefix)}`, 'gmi');
|
const $regex = new RegExp(`\\A${escapeRegExp(prefix)}`, 'gmi');
|
||||||
const filter = { $or: [{ pid: { $regex } }, { title: { $regex } }] };
|
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[]) {
|
static async getListStatus(domainId: string, uid: number, pids: number[]) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ async function executeCommand(input: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.stdin.setEncoding('utf-8');
|
process.stdin.setEncoding('utf-8');
|
||||||
if (process.stdin.setRawMode) process.stdin.setRawMode(false);
|
process.stdin.setRawMode?.(false);
|
||||||
process.stdin.on('data', (buf) => {
|
process.stdin.on('data', (buf) => {
|
||||||
const input = buf.toString();
|
const input = buf.toString();
|
||||||
executeCommand(input);
|
executeCommand(input);
|
||||||
|
|||||||
@@ -842,6 +842,11 @@ const scripts: UpgradeScript[] = [
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
async function _68_69() {
|
||||||
|
const _FRESH_INSTALL_IGNORE = 1;
|
||||||
|
await db.collection('cache' as any).deleteMany({});
|
||||||
|
return true;
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export default scripts;
|
export default scripts;
|
||||||
Reference in new issue
Block a user