mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: problem.getPrefixList: handle pid
This commit is contained in:
1 parent
af91a6307d
commit
e479d5266e
3 files changed
+10
-5
No files matched your search
@@ -35,6 +35,7 @@ import * as bus from '../service/bus';
|
|||||||
import {
|
import {
|
||||||
Handler, param, post, query, route, Types,
|
Handler, param, post, query, route, Types,
|
||||||
} from '../service/server';
|
} from '../service/server';
|
||||||
|
import { buildProjection } from '../utils';
|
||||||
import { registerResolver, registerValue } from './api';
|
import { registerResolver, registerValue } from './api';
|
||||||
import { ContestDetailBaseHandler } from './contest';
|
import { ContestDetailBaseHandler } from './contest';
|
||||||
|
|
||||||
@@ -992,15 +993,19 @@ export class ProblemCreateHandler extends Handler {
|
|||||||
export class ProblemPrefixListHandler extends Handler {
|
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, pdoc] = await Promise.all([
|
const projection = ['domainId', 'docId', 'pid', 'title'] as const;
|
||||||
|
const [pdocs, pdoc, apdoc] = await Promise.all([
|
||||||
problem.getPrefixList(domainId, prefix),
|
problem.getPrefixList(domainId, prefix),
|
||||||
problem.get(domainId, Number.isSafeInteger(+prefix) ? +prefix : prefix, ['domainId', 'docId', 'pid', 'title']),
|
problem.get(domainId, Number.isSafeInteger(+prefix) ? +prefix : prefix, projection),
|
||||||
|
/^P\d+$/.test(prefix) ? problem.get(domainId, +prefix.substring(1), projection) : Promise.resolve(null),
|
||||||
]);
|
]);
|
||||||
|
if (apdoc) pdocs.unshift(apdoc);
|
||||||
if (pdoc) pdocs.unshift(pdoc);
|
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]) } })
|
||||||
|
.project(buildProjection(projection)).toArray();
|
||||||
pdocs.push(...docs);
|
pdocs.push(...docs);
|
||||||
}
|
}
|
||||||
this.response.body = uniqBy(pdocs, 'docId');
|
this.response.body = uniqBy(pdocs, 'docId');
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export type NestKeys<O, T = any, S = any[]> = O extends object ? O extends S ? n
|
|||||||
export type Value<O, V = ''> = {
|
export type Value<O, V = ''> = {
|
||||||
[K in keyof O]: V
|
[K in keyof O]: V
|
||||||
};
|
};
|
||||||
export type Projection<O> = (string & keyof O)[];
|
export type Projection<O> = readonly (string & keyof O)[];
|
||||||
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
|
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
|
||||||
export type Filter<T, U> = T extends U ? T : never;
|
export type Filter<T, U> = T extends U ? T : never;
|
||||||
export type MaybeArray<T> = T | T[];
|
export type MaybeArray<T> = T | T[];
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export function buildProjection(fields: Array<string | number>): Record<string, 1> {
|
export function buildProjection(fields: readonly (string | number)[]): Record<string, 1> {
|
||||||
const o = {};
|
const o = {};
|
||||||
for (const k of fields) o[k] = 1;
|
for (const k of fields) o[k] = 1;
|
||||||
return o;
|
return o;
|
||||||
|
|||||||
Reference in new issue
Block a user