From b2fe14ffe707d441912332865a9c7e6fd4bfe37a Mon Sep 17 00:00:00 2001 From: undefined Date: Sun, 20 Jun 2021 11:48:31 +0800 Subject: [PATCH] core: fullStatus --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/handler/record.ts | 39 +++++++++---------- packages/hydrooj/src/model/record.ts | 17 -------- packages/ui-default/package.json | 2 +- .../ui-default/templates/problem_detail.html | 4 +- 5 files changed, 23 insertions(+), 41 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 94061d891..f6e80169b 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.28.43", + "version": "2.28.44", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/handler/record.ts b/packages/hydrooj/src/handler/record.ts index 653a5b7df..980df4432 100644 --- a/packages/hydrooj/src/handler/record.ts +++ b/packages/hydrooj/src/handler/record.ts @@ -25,10 +25,15 @@ class RecordListHandler extends Handler { @param('tid', Types.ObjectID, true) @param('uidOrName', Types.Name, true) @param('status', Types.Int, true) + @param('fullStatus', Types.Boolean) @param('allDomain', Types.Boolean, true) - async get(domainId: string, page = 1, pid?: string, tid?: ObjectID, uidOrName?: string, status?: number, all = false) { + async get( + domainId: string, page = 1, pid?: string, tid?: ObjectID, + uidOrName?: string, status?: number, full = false, all = false, + ) { this.response.template = 'record_main.html'; const q: FilterQuery = { 'contest.tid': tid, hidden: false }; + if (full) uidOrName = this.user._id.toString(); if (tid) { const tdoc = await contest.get(domainId, tid, -1); if (!tdoc) throw new ContestNotFoundError(domainId, pid); @@ -49,27 +54,21 @@ class RecordListHandler extends Handler { else q.pid = null; } if (status) q.status = status; - const [rdocs] = await paginate( - record.getMulti(domainId, q).sort('_id', -1).project(buildProjection(record.PROJECTION_LIST)), - page, - system.get('pagination.record'), - ); + let cursor = record.getMulti(domainId, q).sort('_id', -1); + if (!full) cursor = cursor.project(buildProjection(record.PROJECTION_LIST)); + const [rdocs] = await paginate(cursor, page, full ? 10 : system.get('pagination.record')); const canViewProblem = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM); const canViewProblemHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN); - const [udict, pdict] = await Promise.all([ - user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)), - canViewProblem - ? problem.getList(domainId, rdocs.map( - (rdoc) => (rdoc.domainId === domainId ? rdoc.pid : `${rdoc.pdomain}:${rdoc.pid}`), - ), canViewProblemHidden, false) - : Object.fromEntries([rdocs.map((rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }])]), - ]); - const path = [ - ['Hydro', 'homepage'], - ['record_main', null], - ]; + const [udict, pdict] = full ? [{}, {}] + : await Promise.all([ + user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)), + canViewProblem + ? problem.getList(domainId, rdocs.map( + (rdoc) => (rdoc.domainId === domainId ? rdoc.pid : `${rdoc.pdomain}:${rdoc.pid}`), + ), canViewProblemHidden, false) + : Object.fromEntries([rdocs.map((rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }])]), + ]); this.response.body = { - path, page, rdocs, pdict, @@ -79,7 +78,7 @@ class RecordListHandler extends Handler { filterUidOrName: uidOrName, filterStatus: status, }; - if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS)) { + if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS) && !full) { this.response.body.statistics = { ...await record.stat(all ? undefined : domainId), delay: await TaskModel.getDelay({ type: 'judge' }), diff --git a/packages/hydrooj/src/model/record.ts b/packages/hydrooj/src/model/record.ts index 221dc03dd..ba70e7aa5 100644 --- a/packages/hydrooj/src/model/record.ts +++ b/packages/hydrooj/src/model/record.ts @@ -202,23 +202,6 @@ class RecordModel { return r; } - @ArgMethod - static getUserInProblemMulti(domainId: string, uid: number, pid: ExternalProblemId | number, contestInfo?: ContestInfo) { - let pdomain = domainId; - if (typeof pid === 'string') { - pdomain = pid.split(':')[0]; - pid = +pid.split(':')[1]; - } - if (!contestInfo) { - return RecordModel.coll.find({ - domainId, uid, pdomain, pid, contest: null, - }); - } - return RecordModel.coll.find({ - domainId, uid, pdomain, pid, contest: contestInfo, - }); - } - @ArgMethod static getByUid(domainId: string, uid: number, limit: number): Promise { return RecordModel.coll.find({ domainId, uid, hidden: false }).sort({ _id: -1 }).limit(limit).toArray(); diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index 5cfa047b7..6fe1b7550 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.11.30", + "version": "4.11.31", "author": "undefined ", "license": "AGPL-3.0", "main": "hydro.js", diff --git a/packages/ui-default/templates/problem_detail.html b/packages/ui-default/templates/problem_detail.html index 4d740fd3d..6cf9f1ff5 100644 --- a/packages/ui-default/templates/problem_detail.html +++ b/packages/ui-default/templates/problem_detail.html @@ -12,13 +12,13 @@ {% if tdoc %} {{ set(UiContext, 'canViewRecord', model.contest.canShowRecord.call(handler, tdoc)) }} {{ set(UiContext, 'postSubmitUrl', url('contest_detail_problem_submit' if tdoc.docType == model.document.TYPE_CONTEST else 'homework_detail_problem_submit', pid=pdoc.pid, tid=tdoc.docId)) }} - {{ set(UiContext, 'getSubmissionsUrl', url('record_main', query={uidOrName:handler.user._id, pid:pdoc.pid, tid:tdoc.docId})) }} + {{ set(UiContext, 'getSubmissionsUrl', url('record_main', query={fullStatus:'true', pid:pdoc.pid, tid:tdoc.docId})) }} {{ set(UiContext, 'getRecordDetailUrl', url('record_detail', rid='{rid}', query={tid:tdoc.docId})) }} {{ set(UiContext, 'pretestConnUrl', "/record-conn?pretest=1&uid=" + handler.user._id + "&pid=" + pdoc.domainId + ":" + pdoc.docId + "&domainId=" + handler.domainId + "&tid=" + tdoc.docId) }} {% else %} {{ set(UiContext, 'canViewRecord', true) }} {{ set(UiContext, 'postSubmitUrl', url('problem_submit', pid=pdoc.docId)) }} - {{ set(UiContext, 'getSubmissionsUrl', url('record_main', query={uidOrName:handler.user._id, pid:pdoc.docId})) }} + {{ set(UiContext, 'getSubmissionsUrl', url('record_main', query={fullStatus:'true', pid:pdoc.docId})) }} {{ set(UiContext, 'getRecordDetailUrl', url('record_detail', rid='{rid}')) }} {{ set(UiContext, 'pretestConnUrl', "/record-conn?pretest=1&uid=" + handler.user._id + "&pid=" + pdoc.docId + "&domainId=" + handler.domainId) }} {% endif %}