core: optimize scoreboard

This commit is contained in:
undefined committed 2022-11-28 23:56:59 +08:00
1 parent f08ac664da
commit af0649f471
13 files changed
+55 -102

No files matched your search

+3 -3
View File
@@ -345,7 +345,7 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
if (!problem.canViewBy(pdoc, this.user)) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN);
}
this.throttleSend = throttle(this.sendUpdate, 1000);
this.throttleSend = throttle(this.sendUpdate, 1000, { trailing: true });
this.rid = rid.toString();
this.cleanup = bus.on('record/change', this.onRecordChange.bind(this));
this.onRecordChange(rdoc);
@@ -368,9 +368,9 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
// TODO: frontend doesn't support incremental update
// if ($set) this.send({ $set, $push });
if (![STATUS.STATUS_WAITING, STATUS.STATUS_JUDGING, STATUS.STATUS_COMPILING, STATUS.STATUS_FETCHED].includes(rdoc.status)) {
this.sendUpdate(rdoc);
this.disconnectTimeout = setTimeout(() => this.close(4001, 'Ended'), 30000);
} else this.throttleSend(rdoc);
}
this.throttleSend(rdoc);
}
}
+3 -7
View File
@@ -4,7 +4,6 @@ import { ProblemNotFoundError, ValidationError } from '../error';
import { Tdoc, TrainingDoc } from '../interface';
import paginate from '../lib/paginate';
import { PERM, PRIV, STATUS } from '../model/builtin';
import DomainModel from '../model/domain';
import problem from '../model/problem';
import * as system from '../model/system';
import * as training from '../model/training';
@@ -108,16 +107,13 @@ class TrainingDetailHandler extends Handler {
}
}
const canViewHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id;
const [udoc, udocs, dudocs, pdict, psdict, selfPsdict] = await Promise.all([
const [udoc, udict, pdict, psdict, selfPsdict] = await Promise.all([
user.getById(domainId, tdoc.owner),
user.getMulti({ _id: { $in: enrollUsers } }).project({ _id: 1, uname: 1, avatar: 1 }).toArray(),
DomainModel.getDomainUserMulti(domainId, enrollUsers).project({ uid: 1, displayName: 1 }).toArray(),
user.getListForRender(domainId, enrollUsers),
problem.getList(domainId, pids, canViewHidden, true),
problem.getListStatus(domainId, targetUser, pids),
shouldCompare ? problem.getListStatus(domainId, this.user._id, pids) : {},
]);
const dudict = {};
for (const dudoc of dudocs) dudict[dudoc.uid] = dudoc.displayName;
const donePids = new Set<number>();
const progPids = new Set<number>();
for (const pid in psdict) {
@@ -151,7 +147,7 @@ class TrainingDetailHandler extends Handler {
done: doneNids.size === tdoc.dag.length,
});
this.response.body = {
tdoc, tsdoc, pids, pdict, psdict, ndict, nsdict, udoc, udocs, dudict, selfPsdict,
tdoc, tsdoc, pids, pdict, psdict, ndict, nsdict, udoc, udict, selfPsdict,
};
this.response.pjax = 'partials/training_detail.html';
this.response.template = 'training_detail.html';