!UNSTABLE 优化数据库结构,为domain功能准备

This commit is contained in:
masnn committed 2020-05-29 13:05:52 +08:00
1 parent 7d27e56018
commit fff2172c38
40 files changed
+1411 -1012

No files matched your search

+23 -15
View File
@@ -13,13 +13,13 @@ const {
} = require('../service/server');
class RecordListHandler extends Handler {
async get({ page = 1 }) {
async get({ domainId, page = 1 }) {
this.response.template = 'record_main.html';
const q = {};
const rdocs = await record.getMany(q, { _id: -1 }, page, await system.get('RECORD_PER_PAGE'));
const rdocs = await record.getMany(domainId, q, { _id: -1 }, page, await system.get('RECORD_PER_PAGE'));
const [udict, pdict] = await Promise.all([
user.getList(rdocs.map((rdoc) => rdoc.uid)),
problem.getList(rdocs.map((rdoc) => rdoc.pid)),
user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)),
problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid)),
]);
const path = [
['Hydro', '/'],
@@ -32,19 +32,23 @@ class RecordListHandler extends Handler {
}
class RecordDetailHandler extends Handler {
async get({ rid }) {
async get({ domainId, rid }) {
this.response.template = 'record_detail.html';
const rdoc = await record.get(rid);
const rdoc = await record.get(domainId, rid);
if (rdoc.hidden) this.checkPerm(PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD);
if (rdoc.uid !== this.user.uid && !this.user.hasPerm(PERM_READ_RECORD_CODE)) {
rdoc.code = null;
}
const pdoc = await problem.getById(rdoc.pid);
const [pdoc, udoc] = await Promise.all([
problem.get(domainId, rdoc.pid),
user.getById(domainId, rdoc.uid),
]);
this.response.body = {
path: [
['Hydro', '/'],
['record_detail', null],
],
udoc,
rdoc,
pdoc,
show_status: true,
@@ -53,16 +57,17 @@ class RecordDetailHandler extends Handler {
}
class RecordRejudgeHandler extends Handler {
async post({ rid }) {
async post({ domainId, rid }) {
this.checkPerm(PERM_REJUDGE);
const rdoc = await record.get(rid);
if (rdoc) await record.rejudge(rid);
const rdoc = await record.get(domainId, rid);
if (rdoc) await record.rejudge(domainId, rid);
this.back();
}
}
class RecordConnectionHandler extends ConnectionHandler {
async prepare() {
async prepare({ domainId }) {
this.domainId = domainId;
bus.subscribe(['record_change'], this.onRecordChange);
}
@@ -81,17 +86,20 @@ class RecordConnectionHandler extends ConnectionHandler {
const rdoc = data.value;
if (rdoc.tid && rdoc.tid.toString() !== this.tid) return;
// eslint-disable-next-line prefer-const
let [udoc, pdoc] = await Promise.all([user.getById(rdoc.uid), problem.getById(rdoc.pid)]);
let [udoc, pdoc] = await Promise.all([
user.getById(this.domainId, rdoc.uid),
problem.getById(this.domainId, rdoc.pid),
]);
if (pdoc.hidden && !this.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) pdoc = null;
this.send({ html: await this.renderHTML('record_main_tr.html', { rdoc, udoc, pdoc }) });
}
}
class RecordDetailConnectionHandler extends contest.ContestHandlerMixin(ConnectionHandler) {
async prepare({ rid }) {
const rdoc = await record.get(rid);
async prepare({ domainId, rid }) {
const rdoc = await record.get(domainId, rid);
if (rdoc.tid) {
const tdoc = await contest.get(rdoc.tid);
const tdoc = await contest.get(domainId, rdoc.tid);
if (!this.canShowRecord(tdoc)) {
this.close();
return;