mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: optimize record connection
This commit is contained in:
1 parent
5e8d2b1286
commit
817eac2923
2 files changed
+15
-8
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "3.16.8",
|
"version": "3.16.9",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { debounce, omit } from 'lodash';
|
||||||
import { FilterQuery, ObjectID } from 'mongodb';
|
import { FilterQuery, ObjectID } from 'mongodb';
|
||||||
import {
|
import {
|
||||||
ContestNotAttendedError, ContestNotFoundError, PermissionError,
|
ContestNotAttendedError, ContestNotFoundError, PermissionError,
|
||||||
@@ -275,7 +276,7 @@ class RecordMainConnectionHandler extends ConnectionHandler {
|
|||||||
if (!problem.canViewBy(pdoc, this.user)) pdoc = null;
|
if (!problem.canViewBy(pdoc, this.user)) pdoc = null;
|
||||||
if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) pdoc = null;
|
if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) pdoc = null;
|
||||||
}
|
}
|
||||||
if (this.pretest) this.send({ rdoc });
|
if (this.pretest) this.send({ rdoc: omit(rdoc, ['code', 'input']) });
|
||||||
else {
|
else {
|
||||||
this.send({
|
this.send({
|
||||||
html: await this.renderHTML('record_main_tr.html', {
|
html: await this.renderHTML('record_main_tr.html', {
|
||||||
@@ -290,6 +291,7 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
|||||||
cleanup: bus.Disposable = () => { };
|
cleanup: bus.Disposable = () => { };
|
||||||
rid: string = '';
|
rid: string = '';
|
||||||
disconnectTimeout: NodeJS.Timeout;
|
disconnectTimeout: NodeJS.Timeout;
|
||||||
|
debounceSend: any;
|
||||||
|
|
||||||
@param('rid', Types.ObjectID)
|
@param('rid', Types.ObjectID)
|
||||||
async prepare(domainId: string, rid: ObjectID) {
|
async prepare(domainId: string, rid: ObjectID) {
|
||||||
@@ -320,11 +322,19 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
|||||||
if (!problem.canViewBy(pdoc, this.user)) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
if (!problem.canViewBy(pdoc, this.user)) throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.debounceSend = debounce(this.send, 1000);
|
||||||
this.rid = rid.toString();
|
this.rid = rid.toString();
|
||||||
this.cleanup = bus.on('record/change', this.onRecordChange.bind(this));
|
this.cleanup = bus.on('record/change', this.onRecordChange.bind(this));
|
||||||
this.onRecordChange(rdoc);
|
this.onRecordChange(rdoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async sendUpdate(rdoc: RecordDoc) {
|
||||||
|
this.send({
|
||||||
|
status_html: await this.renderHTML('record_detail_status.html', { rdoc }),
|
||||||
|
summary_html: await this.renderHTML('record_detail_summary.html', { rdoc }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
async onRecordChange(rdoc: RecordDoc, $set?: any, $push?: any) {
|
async onRecordChange(rdoc: RecordDoc, $set?: any, $push?: any) {
|
||||||
if (rdoc._id.toString() !== this.rid) return;
|
if (rdoc._id.toString() !== this.rid) return;
|
||||||
@@ -334,13 +344,10 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
|||||||
}
|
}
|
||||||
// TODO: frontend doesn't support incremental update
|
// TODO: frontend doesn't support incremental update
|
||||||
// if ($set) this.send({ $set, $push });
|
// if ($set) this.send({ $set, $push });
|
||||||
this.send({
|
|
||||||
status_html: await this.renderHTML('record_detail_status.html', { rdoc }),
|
|
||||||
summary_html: await this.renderHTML('record_detail_summary.html', { rdoc }),
|
|
||||||
});
|
|
||||||
if (![STATUS.STATUS_WAITING, STATUS.STATUS_JUDGING, STATUS.STATUS_COMPILING, STATUS.STATUS_FETCHED].includes(rdoc.status)) {
|
if (![STATUS.STATUS_WAITING, STATUS.STATUS_JUDGING, STATUS.STATUS_COMPILING, STATUS.STATUS_FETCHED].includes(rdoc.status)) {
|
||||||
this.disconnectTimeout = setTimeout(() => this.close(4001, 'Ended'), 10000);
|
this.sendUpdate(rdoc);
|
||||||
}
|
this.disconnectTimeout = setTimeout(() => this.close(4001, 'Ended'), 30000);
|
||||||
|
} else this.debounceSend(rdoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user