mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: record_list: add projection
This commit is contained in:
1 parent
36f356340c
commit
99ddb9c92e
2 files changed
+14
-5
No files matched your search
@@ -13,6 +13,7 @@ import * as bus from '../service/bus';
|
|||||||
import {
|
import {
|
||||||
Route, Handler, Connection, ConnectionHandler, Types, param,
|
Route, Handler, Connection, ConnectionHandler, Types, param,
|
||||||
} from '../service/server';
|
} from '../service/server';
|
||||||
|
import { buildProjection } from '../utils';
|
||||||
|
|
||||||
class RecordListHandler extends Handler {
|
class RecordListHandler extends Handler {
|
||||||
@param('page', Types.PositiveInt, true)
|
@param('page', Types.PositiveInt, true)
|
||||||
@@ -45,7 +46,7 @@ class RecordListHandler extends Handler {
|
|||||||
}
|
}
|
||||||
if (status) q.status = status;
|
if (status) q.status = status;
|
||||||
const [rdocs] = await paginate(
|
const [rdocs] = await paginate(
|
||||||
record.getMulti(domainId, q).sort('_id', -1),
|
record.getMulti(domainId, q).sort('_id', -1).project(buildProjection(record.PROJECTION_LIST)),
|
||||||
page,
|
page,
|
||||||
system.get('pagination.record'),
|
system.get('pagination.record'),
|
||||||
);
|
);
|
||||||
@@ -70,6 +71,7 @@ class RecordListHandler extends Handler {
|
|||||||
filterPid: pid,
|
filterPid: pid,
|
||||||
filterTid: tid,
|
filterTid: tid,
|
||||||
filterUidOrName: uidOrName,
|
filterUidOrName: uidOrName,
|
||||||
|
filterStatus: status,
|
||||||
};
|
};
|
||||||
if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS)) {
|
if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS)) {
|
||||||
this.response.body.statistics = {
|
this.response.body.statistics = {
|
||||||
|
|||||||
@@ -9,13 +9,18 @@ import { STATUS } from './builtin';
|
|||||||
import task from './task';
|
import task from './task';
|
||||||
import problem from './problem';
|
import problem from './problem';
|
||||||
import { Rdoc, ContestInfo, ProblemConfig } from '../interface';
|
import { Rdoc, ContestInfo, ProblemConfig } from '../interface';
|
||||||
import { ArgMethod, Time } from '../utils';
|
import { ArgMethod, buildProjection, Time } from '../utils';
|
||||||
import { MaybeArray } from '../typeutils';
|
import { MaybeArray } from '../typeutils';
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
import db from '../service/db';
|
import db from '../service/db';
|
||||||
|
|
||||||
class RecordModel {
|
class RecordModel {
|
||||||
static coll: Collection<Rdoc> = db.collection('record');
|
static coll: Collection<Rdoc> = 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) {
|
static async submissionPriority(uid: number, base: number = 0) {
|
||||||
const pending = await task.count({ uid });
|
const pending = await task.count({ uid });
|
||||||
@@ -169,11 +174,13 @@ class RecordModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getList(
|
static async getList(
|
||||||
domainId: string, rids: ObjectID[], showHidden: boolean,
|
domainId: string, rids: ObjectID[], showHidden: boolean, fields?: (keyof Rdoc)[],
|
||||||
): Promise<Record<string, Rdoc>> {
|
): Promise<Record<string, Partial<Rdoc>>> {
|
||||||
const r = {};
|
const r = {};
|
||||||
rids = Array.from(new Set(rids));
|
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) {
|
for (const rdoc of rdocs) {
|
||||||
if (rdoc.hidden && !showHidden) r[rdoc._id.toHexString()] = null;
|
if (rdoc.hidden && !showHidden) r[rdoc._id.toHexString()] = null;
|
||||||
else r[rdoc._id.toHexString()] = rdoc;
|
else r[rdoc._id.toHexString()] = rdoc;
|
||||||
|
|||||||
Reference in new issue
Block a user