mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: remove pdoc.psdoc hack
This commit is contained in:
1 parent
c0a3f235ca
commit
71f86cf79b
7 files changed
+21
-37
No files matched your search
@@ -247,7 +247,7 @@ class ContestProblemHandler extends Handler {
|
||||
async _prepare(domainId: string, tid: ObjectID, pid: number) {
|
||||
[this.tdoc, this.pdoc] = await Promise.all([
|
||||
contest.get(domainId, tid),
|
||||
problem.get(domainId, pid, this.user._id),
|
||||
problem.get(domainId, pid),
|
||||
]);
|
||||
[this.tsdoc, this.udoc] = await Promise.all([
|
||||
contest.getStatus(domainId, this.tdoc.docId, this.user._id),
|
||||
|
||||
@@ -132,7 +132,7 @@ class HomeworkDetailProblemHandler extends Handler {
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM);
|
||||
[this.tdoc, this.pdoc, this.tsdoc] = await Promise.all([
|
||||
contest.get(domainId, tid, document.TYPE_HOMEWORK),
|
||||
problem.get(domainId, pid, this.user._id),
|
||||
problem.get(domainId, pid),
|
||||
contest.getStatus(domainId, tid, this.user._id, document.TYPE_HOMEWORK),
|
||||
]);
|
||||
this.udoc = await user.getById(domainId, this.tdoc.owner);
|
||||
|
||||
@@ -98,7 +98,7 @@ export class ProblemMainHandler extends ProblemHandler {
|
||||
);
|
||||
if (sort) pdocs = pdocs.sort((a, b) => sort.indexOf(a.docId) - sort.indexOf(b.docId));
|
||||
if (q && +q) {
|
||||
const pdoc = await problem.get(domainId, +q, this.user._id, problem.PROJECTION_LIST);
|
||||
const pdoc = await problem.get(domainId, +q, problem.PROJECTION_LIST);
|
||||
if (pdoc) pdocs.unshift(pdoc);
|
||||
}
|
||||
if (this.user.hasPriv(PRIV.PRIV_USER_PROFILE)) {
|
||||
@@ -174,24 +174,24 @@ export class ProblemRandomHandler extends ProblemHandler {
|
||||
}
|
||||
}
|
||||
|
||||
export interface PdocWithPsdoc extends ProblemDoc {
|
||||
psdoc?: ProblemStatusDoc
|
||||
}
|
||||
|
||||
export class ProblemDetailHandler extends ProblemHandler {
|
||||
pdoc: PdocWithPsdoc;
|
||||
pdoc: ProblemDoc;
|
||||
udoc: User;
|
||||
psdoc: ProblemStatusDoc;
|
||||
|
||||
@route('pid', Types.Name, true, null, parsePid)
|
||||
async _prepare(domainId: string, pid: number | string) {
|
||||
this.response.template = 'problem_detail.html';
|
||||
this.pdoc = await problem.get(domainId, pid, this.user._id);
|
||||
this.pdoc = await problem.get(domainId, pid);
|
||||
if (!this.pdoc) throw new ProblemNotFoundError(domainId, pid);
|
||||
if (this.pdoc.hidden && !this.user.own(this.pdoc)) {
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
}
|
||||
await bus.serial('problem/get', this.pdoc, this);
|
||||
this.udoc = await user.getById(domainId, this.pdoc.owner);
|
||||
[this.psdoc, this.udoc] = await Promise.all([
|
||||
problem.getStatus(domainId, this.pdoc.docId, this.user._id),
|
||||
user.getById(domainId, this.pdoc.owner),
|
||||
]);
|
||||
this.response.body = {
|
||||
pdoc: this.pdoc,
|
||||
udoc: this.udoc,
|
||||
@@ -219,8 +219,8 @@ export class ProblemDetailHandler extends ProblemHandler {
|
||||
this.response.body.pdoc.content = this.response.body.pdoc.content
|
||||
.replace(/\(file:\/\//g, `(./${this.pdoc.docId}/file/`);
|
||||
}
|
||||
if (this.pdoc.psdoc) {
|
||||
this.response.body.rdoc = await record.get(this.domainId, this.pdoc.psdoc.rid);
|
||||
if (this.psdoc) {
|
||||
this.response.body.rdoc = await record.get(this.domainId, this.psdoc.rid);
|
||||
}
|
||||
this.response.body.ctdocs = await contest.getRelated(this.domainId, this.pdoc.docId);
|
||||
}
|
||||
@@ -599,7 +599,7 @@ export class ProblemPrefixListHandler extends Handler {
|
||||
async get(domainId: string, prefix: string) {
|
||||
this.response.body = await problem.getPrefixList(domainId, prefix);
|
||||
if (!Number.isNaN(+prefix)) {
|
||||
const pdoc = await problem.get(domainId, +prefix, undefined, ['domainId', 'docId', 'pid', 'title']);
|
||||
const pdoc = await problem.get(domainId, +prefix, ['domainId', 'docId', 'pid', 'title']);
|
||||
if (pdoc) this.response.body.unshift(pdoc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ export function deleteMultiStatus<K extends keyof DocStatusType>(
|
||||
export function getMulti<K extends keyof DocType>(
|
||||
domainId: string, docType: K, query?: FilterQuery<DocType[K]>, projection?: Projection<DocType[K]>,
|
||||
): Cursor<DocType[K]> {
|
||||
let cursor = coll.find({ ...query, docType, domainId });
|
||||
let cursor = coll.find({ docType, domainId, ...query });
|
||||
if (projection) cursor = cursor.project(buildProjection(projection));
|
||||
return cursor;
|
||||
}
|
||||
|
||||
@@ -74,25 +74,24 @@ export class ProblemModel {
|
||||
|
||||
static async get(
|
||||
domainId: string, pid: string | number,
|
||||
uid: number = null, projection: Projection<ProblemDoc> = ProblemModel.PROJECTION_PUBLIC,
|
||||
projection: Projection<ProblemDoc> = ProblemModel.PROJECTION_PUBLIC,
|
||||
): Promise<ProblemDoc> {
|
||||
if (typeof pid !== 'number') {
|
||||
if (Number.isSafeInteger(parseInt(pid, 10))) pid = parseInt(pid, 10);
|
||||
}
|
||||
const pdoc = typeof pid === 'number'
|
||||
return typeof pid === 'number'
|
||||
? await document.get(domainId, document.TYPE_PROBLEM, pid, projection)
|
||||
: (await document.getMulti(domainId, document.TYPE_PROBLEM, { pid }).toArray())[0];
|
||||
if (!pdoc) return null;
|
||||
if (uid) {
|
||||
pdoc.psdoc = await document.getStatus(domainId, document.TYPE_PROBLEM, pdoc.docId, uid);
|
||||
}
|
||||
return pdoc;
|
||||
}
|
||||
|
||||
static getMulti(domainId: string, query: FilterQuery<ProblemDoc>, projection = ProblemModel.PROJECTION_LIST) {
|
||||
return document.getMulti(domainId, document.TYPE_PROBLEM, query, projection);
|
||||
}
|
||||
|
||||
static getStatus(domainId: string, docId: number, uid: number) {
|
||||
return document.getStatus(domainId, document.TYPE_PROBLEM, docId, uid);
|
||||
}
|
||||
|
||||
static getMultiStatus(domainId: string, query: FilterQuery<ProblemDoc>) {
|
||||
return document.getMultiStatus(domainId, document.TYPE_PROBLEM, query);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ async function runProblem(pdoc: ProblemDoc, udict: ND): Promise<void>;
|
||||
async function runProblem(domainId: string, pid: number, udict: ND): Promise<void>;
|
||||
async function runProblem(...arg: any[]) {
|
||||
const pdoc: ProblemDoc = (typeof arg[0] === 'string')
|
||||
? await problem.get(arg[0], arg[1], -1)
|
||||
? await problem.get(arg[0], arg[1])
|
||||
: arg[0];
|
||||
const udict: ND = (typeof arg[0] === 'string') ? arg[2] : arg[1];
|
||||
const [, nPages] = await paginate(
|
||||
|
||||
@@ -9,21 +9,6 @@
|
||||
<dd>{{ pdoc.config.timeMax if pdoc.config.timeMax == pdoc.config.timeMin else pdoc.config.timeMin+'~'+pdoc.config.timeMax }}ms</dd>
|
||||
<dt>{{ _('Memory') }}</dt>
|
||||
<dd>{{ pdoc.config.memoryMax if pdoc.config.memoryMax == pdoc.config.memoryMin else pdoc.config.memoryMin+'~'+pdoc.config.memoryMax }}MiB</dd>
|
||||
{% if page_name != 'discussion_node' and page_name != 'discussion_detail' %}
|
||||
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
|
||||
<dt>{{ _('Submission') }}</dt>
|
||||
<dd>
|
||||
{% if pdoc.psdoc.status %}
|
||||
<span class="icon record-status--icon {{ model.builtin.STATUS_CODES[pdoc['psdoc']['status']] }}"></span>
|
||||
<a href="{{ url('record_detail', rid=pdoc.psdoc.rid) }}" class="record-status--text {{ model.builtin.STATUS_CODES[pdoc['psdoc']['status']] }}">
|
||||
{{ model.builtin.STATUS_TEXTS[pdoc['psdoc']['status']] }}
|
||||
</a>
|
||||
{% else %}
|
||||
{{ _('(None)') }}
|
||||
{% endif %}
|
||||
</dd>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<dt>{{ _('Difficulty') }}</dt>
|
||||
<dd>{{ pdoc['difficulty'] or _('(None)') }}</dd>
|
||||
<dt>{{ _('Category') }}</dt>
|
||||
|
||||
Reference in new issue
Block a user