core: problemlist: support optional limit param

This commit is contained in:
undefined committed 2022-12-31 16:32:14 +08:00
1 parent 5245dfd3f6
commit d311e9366a
1 file changed
+6 -8
+6 -8
View File
@@ -136,9 +136,11 @@ const defaultSearch = async (domainId: string, q: string, options?: ProblemSearc
export class ProblemMainHandler extends Handler { export class ProblemMainHandler extends Handler {
@param('page', Types.PositiveInt, true) @param('page', Types.PositiveInt, true)
@param('q', Types.Content, true) @param('q', Types.Content, true)
@param('limit', Types.PositiveInt, true)
@param('pjax', Types.Boolean) @param('pjax', Types.Boolean)
async get(domainId: string, page = 1, q = '', pjax = false) { async get(domainId: string, page = 1, q = '', limit: number, pjax = false) {
this.response.template = 'problem_main.html'; this.response.template = 'problem_main.html';
if (!limit || limit > system.get('pagination.problem') || page > 1) limit = system.get('pagination.problem');
// eslint-disable-next-line @typescript-eslint/no-shadow // eslint-disable-next-line @typescript-eslint/no-shadow
const query = buildQuery(this.user); const query = buildQuery(this.user);
const psdict = {}; const psdict = {};
@@ -155,7 +157,7 @@ export class ProblemMainHandler extends Handler {
if (category.length) this.UiContext.extraTitleContent = category.join(','); if (category.length) this.UiContext.extraTitleContent = category.join(',');
let total = 0; let total = 0;
if (text) { if (text) {
const result = await search(domainId, q, { skip: (page - 1) * system.get('pagination.problem') }); const result = await search(domainId, q, { skip: (page - 1) * limit });
total = result.total; total = result.total;
pcountRelation = result.countRelation; pcountRelation = result.countRelation;
if (!result.hits.length) fail = true; if (!result.hits.length) fail = true;
@@ -172,14 +174,10 @@ export class ProblemMainHandler extends Handler {
// eslint-disable-next-line prefer-const // eslint-disable-next-line prefer-const
let [pdocs, ppcount, pcount] = fail let [pdocs, ppcount, pcount] = fail
? [[], 0, 0] ? [[], 0, 0]
: await problem.list( : await problem.list(domainId, query, sort?.length ? 1 : page, limit, undefined, this.user._id);
domainId, query,
sort?.length ? 1 : page, system.get('pagination.problem'),
undefined, this.user._id,
);
if (total) { if (total) {
pcount = total; pcount = total;
ppcount = Math.ceil(total / system.get('pagination.problem')); ppcount = Math.ceil(total / limit);
} }
if (sort) pdocs = pdocs.sort((a, b) => sort.indexOf(`${a.domainId}/${a.docId}`) - sort.indexOf(`${b.domainId}/${b.docId}`)); if (sort) pdocs = pdocs.sort((a, b) => sort.indexOf(`${a.domainId}/${a.docId}`) - sort.indexOf(`${b.domainId}/${b.docId}`));
if (q && page === 1) { if (q && page === 1) {