From 99ddb9c92e14a5ff137f65ab1bade657545606b5 Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 6 May 2021 14:06:33 +0800 Subject: [PATCH] core: record_list: add projection --- packages/hydrooj/src/handler/record.ts | 4 +++- packages/hydrooj/src/model/record.ts | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/hydrooj/src/handler/record.ts b/packages/hydrooj/src/handler/record.ts index 060d64394..3c2572651 100644 --- a/packages/hydrooj/src/handler/record.ts +++ b/packages/hydrooj/src/handler/record.ts @@ -13,6 +13,7 @@ import * as bus from '../service/bus'; import { Route, Handler, Connection, ConnectionHandler, Types, param, } from '../service/server'; +import { buildProjection } from '../utils'; class RecordListHandler extends Handler { @param('page', Types.PositiveInt, true) @@ -45,7 +46,7 @@ class RecordListHandler extends Handler { } if (status) q.status = status; const [rdocs] = await paginate( - record.getMulti(domainId, q).sort('_id', -1), + record.getMulti(domainId, q).sort('_id', -1).project(buildProjection(record.PROJECTION_LIST)), page, system.get('pagination.record'), ); @@ -70,6 +71,7 @@ class RecordListHandler extends Handler { filterPid: pid, filterTid: tid, filterUidOrName: uidOrName, + filterStatus: status, }; if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS)) { this.response.body.statistics = { diff --git a/packages/hydrooj/src/model/record.ts b/packages/hydrooj/src/model/record.ts index da12aa7e9..d626eabc7 100644 --- a/packages/hydrooj/src/model/record.ts +++ b/packages/hydrooj/src/model/record.ts @@ -9,13 +9,18 @@ import { STATUS } from './builtin'; import task from './task'; import problem from './problem'; import { Rdoc, ContestInfo, ProblemConfig } from '../interface'; -import { ArgMethod, Time } from '../utils'; +import { ArgMethod, buildProjection, Time } from '../utils'; import { MaybeArray } from '../typeutils'; import * as bus from '../service/bus'; import db from '../service/db'; class RecordModel { static coll: Collection = db.collection('record'); + static PROJECTION_LIST: (keyof Rdoc)[] = [ + '_id', 'score', 'time', 'memory', 'lang', + 'uid', 'pid', 'rejudged', 'hidden', 'progress', + 'contest', 'effective', 'judger', 'judgeAt', + ]; static async submissionPriority(uid: number, base: number = 0) { const pending = await task.count({ uid }); @@ -169,11 +174,13 @@ class RecordModel { } static async getList( - domainId: string, rids: ObjectID[], showHidden: boolean, - ): Promise> { + domainId: string, rids: ObjectID[], showHidden: boolean, fields?: (keyof Rdoc)[], + ): Promise>> { const r = {}; rids = Array.from(new Set(rids)); - const rdocs = await RecordModel.coll.find({ domainId, _id: { $in: rids } }).toArray(); + let cursor = RecordModel.coll.find({ domainId, _id: { $in: rids } }); + if (fields) cursor = cursor.project(buildProjection(fields)); + const rdocs = await cursor.toArray(); for (const rdoc of rdocs) { if (rdoc.hidden && !showHidden) r[rdoc._id.toHexString()] = null; else r[rdoc._id.toHexString()] = rdoc;