mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: record_detail: use throttle instead of debounce
This commit is contained in:
1 parent
c63d7c16c1
commit
f4b12ef004
4 files changed
+10
-9
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "4.0.2",
|
"version": "4.0.3",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/plugin-api",
|
"main": "src/plugin-api",
|
||||||
"module": "src/plugin-api",
|
"module": "src/plugin-api",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
|
import { omit } from 'lodash';
|
||||||
import { ObjectID } from 'mongodb';
|
import { ObjectID } from 'mongodb';
|
||||||
import {
|
import {
|
||||||
JudgeResultBody, ProblemConfigFile, RecordDoc, TestCase,
|
JudgeResultBody, ProblemConfigFile, RecordDoc, TestCase,
|
||||||
@@ -209,7 +210,7 @@ class JudgeConnectionHandler extends ConnectionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async message(msg) {
|
async message(msg) {
|
||||||
if (msg.key !== 'ping' && msg.key !== 'prio') logger[['status', 'next'].includes(msg.key) ? 'debug' : 'info']('%o', msg);
|
if (msg.key !== 'ping' && msg.key !== 'prio') logger[['status', 'next'].includes(msg.key) ? 'debug' : 'info']('%o', omit(msg, 'key'));
|
||||||
if (msg.key === 'next') await next(msg);
|
if (msg.key === 'next') await next(msg);
|
||||||
else if (msg.key === 'end') {
|
else if (msg.key === 'end') {
|
||||||
if (!msg.nop) await end({ judger: this.user._id, ...msg }).catch((e) => logger.error(e));
|
if (!msg.nop) await end({ judger: this.user._id, ...msg }).catch((e) => logger.error(e));
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { debounce, omit } from 'lodash';
|
import { omit, throttle } from 'lodash';
|
||||||
import { FilterQuery, ObjectID } from 'mongodb';
|
import { FilterQuery, ObjectID } from 'mongodb';
|
||||||
import {
|
import {
|
||||||
ContestNotAttendedError, ContestNotFoundError, ForbiddenError, PermissionError,
|
ContestNotAttendedError, ContestNotFoundError, ForbiddenError, PermissionError,
|
||||||
@@ -303,7 +303,7 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
|||||||
cleanup: bus.Disposable = () => { };
|
cleanup: bus.Disposable = () => { };
|
||||||
rid: string = '';
|
rid: string = '';
|
||||||
disconnectTimeout: NodeJS.Timeout;
|
disconnectTimeout: NodeJS.Timeout;
|
||||||
debounceSend: any;
|
throttleSend: any;
|
||||||
|
|
||||||
@param('rid', Types.ObjectID)
|
@param('rid', Types.ObjectID)
|
||||||
async prepare(domainId: string, rid: ObjectID) {
|
async prepare(domainId: string, rid: ObjectID) {
|
||||||
@@ -334,7 +334,7 @@ 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.throttleSend = throttle(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);
|
||||||
@@ -359,7 +359,7 @@ class RecordDetailConnectionHandler extends ConnectionHandler {
|
|||||||
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.sendUpdate(rdoc);
|
this.sendUpdate(rdoc);
|
||||||
this.disconnectTimeout = setTimeout(() => this.close(4001, 'Ended'), 30000);
|
this.disconnectTimeout = setTimeout(() => this.close(4001, 'Ended'), 30000);
|
||||||
} else this.debounceSend(rdoc);
|
} else this.throttleSend(rdoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import { ObjectID } from 'mongodb';
|
|||||||
import Logger from 'reggol';
|
import Logger from 'reggol';
|
||||||
|
|
||||||
Logger.levels.base = process.env.DEV ? 3 : 2;
|
Logger.levels.base = process.env.DEV ? 3 : 2;
|
||||||
Logger.targets[0].showTime = 'MM/dd hh:mm:ss';
|
Logger.targets[0].showTime = 'dd hh:mm:ss';
|
||||||
Logger.targets[0].label = {
|
Logger.targets[0].label = {
|
||||||
align: 'right',
|
align: 'right',
|
||||||
width: 10,
|
width: 9,
|
||||||
margin: 2,
|
margin: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
export { Logger };
|
export { Logger };
|
||||||
|
|||||||
Reference in new issue
Block a user