From 29556f964df026155578c7ebd59d199be419a7e6 Mon Sep 17 00:00:00 2001 From: undefined Date: Sun, 24 Nov 2024 18:11:38 +0800 Subject: [PATCH] core: allow modifying problem_main query hint --- packages/hydrooj/src/handler/problem.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 451f51f8b..e29d09b52 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -81,6 +81,7 @@ export interface QueryContext { text: string; total: number; fail: boolean; + hint: string; } export class ProblemMainHandler extends Handler { @@ -93,6 +94,7 @@ export class ProblemMainHandler extends Handler { text: '', total: 0, fail: false, + hint: 'sort', }; @param('page', Types.PositiveInt, true) @@ -134,13 +136,8 @@ export class ProblemMainHandler extends Handler { total = result.total; this.queryContext.pcountRelation = result.countRelation; if (!result.hits.length) this.queryContext.fail = true; - query.$and ||= []; - query.$and.push({ - $or: result.hits.map((i) => { - const [did, docId] = i.split('/'); - return { domainId: did, docId: +docId }; - }), - }); + query.docId = { $in: result.hits.map((t) => +t.split('/')[1]) }; + this.queryContext.hint = 'basic'; this.queryContext.sort = result.hits; } const sort = this.queryContext.sort; @@ -150,7 +147,7 @@ export class ProblemMainHandler extends Handler { ? [[], 0, 0] : await this.paginate( problem.getMulti(domainId, query, quick ? ['title', 'pid', 'domainId', 'docId'] : undefined) - .sort({ sort: 1, docId: 1 }).hint('sort'), + .sort({ sort: 1, docId: 1 }).hint(this.queryContext.hint), sort.length ? 1 : page, limit, ); if (total) {