优化rating计算速度

This commit is contained in:
masnn committed 2020-06-09 13:22:04 +08:00
1 parent 45f1184d68
commit 55912b087d
22 files changed
+309 -178

No files matched your search

+2 -2
View File
@@ -282,7 +282,7 @@ class ContestCreateHandler extends ContestHandler {
}
async post({
domainId, title, content, rule, beginAtDate, beginAtTime, duration, pids,
domainId, title, content, rule, beginAtDate, beginAtTime, duration, pids, rated = false,
}) {
let beginAt;
try {
@@ -294,7 +294,7 @@ class ContestCreateHandler extends ContestHandler {
pids = await this.verifyProblems(domainId, pids);
const tid = await contest.add(
domainId, title, content,
this.user._id, rule, beginAt, endAt, pids,
this.user._id, rule, beginAt, endAt, pids, rated,
);
this.response.body = { tid };
this.response.redirect = `/c/${tid}`;
+7 -2
View File
@@ -95,7 +95,12 @@ class DomainUserHandler extends ManageHandler {
const uids = [];
const rudocs = {};
const [udocs, roles] = await Promise.all([
user.getInDomain(domainId),
user.getMultiInDomain(domainId, {
$and: [
{ role: { $ne: 'default' } },
{ role: { $ne: null } },
],
}).toArray(),
user.getRoles(domainId),
]);
for (const role of roles) rudocs[role._id] = [];
@@ -104,7 +109,7 @@ class DomainUserHandler extends ManageHandler {
// TODO Improve here
// eslint-disable-next-line no-await-in-loop
const ud = await user.getById(domainId, udoc.uid);
rudocs[udoc.role].push({ ...ud, role: udoc.role });
rudocs[ud.role].push(ud);
}
const rolesSelect = roles.map((role) => [role._id, role._id]);
const udict = await user.getList(domainId, uids);
+2 -2
View File
@@ -197,7 +197,7 @@ class HomeworkCreateHandler extends HomeworkHandler {
async post({
domainId, title, content, beginAtDate, beginAtTime,
penaltySinceDate, penaltySinceTime, extensionDays,
penaltyRules, pids,
penaltyRules, pids, rated = false,
}) {
let beginAt;
let penaltySince;
@@ -216,7 +216,7 @@ class HomeworkCreateHandler extends HomeworkHandler {
if (penaltySince > endAt) throw new ValidationError('extensionDays');
await this.verifyProblems(domainId, pids);
const tid = await contest.add(domainId, title, content, this.user._id,
'homework', beginAt, endAt, pids, { penaltySince, penaltyRules }, document.TYPE_HOMEWORK);
'homework', beginAt, endAt, pids, rated, { penaltySince, penaltyRules }, document.TYPE_HOMEWORK);
this.response.body = { tid };
this.response.redirect = `/homework/${tid}`;
}
+2 -2
View File
@@ -8,7 +8,7 @@ const { PermissionError } = require('../error');
class SystemHandler extends Handler {
async prepare() {
if (!this.user.priv) throw new PermissionError('???');
this.body = {
this.response.body = {
path: [
['Hydro', '/'],
['manage_main', '/manage'],
@@ -58,7 +58,7 @@ class SystemScriptHandler extends SystemHandler {
async post({ id, args }) {
// TODO Do not use console.log
await global.Hydro.script[id].run(args, console.log);
await global.Hydro.script[id].run(JSON.parse(args), console.log);
this.back();
}
}
+1 -1
View File
@@ -176,7 +176,7 @@ class ProblemSubmitHandler extends ProblemDetailHandler {
});
await Promise.all([
record.judge(domainId, rid),
user.inc(this.user._id, 'nSubmit'),
user.incDomain(domainId, this.user._id, 'nSubmit'),
]);
this.response.body = { rid };
this.response.redirect = `/r/${rid}`;