mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: reset compression regularly
This commit is contained in:
1 file changed
+13
-5
@@ -366,12 +366,23 @@ export function Route(name: string, path: string, RouteHandler: any, ...permPriv
|
|||||||
export class ConnectionHandler extends HandlerCommon {
|
export class ConnectionHandler extends HandlerCommon {
|
||||||
conn: WebSocket;
|
conn: WebSocket;
|
||||||
compression: Shorty;
|
compression: Shorty;
|
||||||
|
counter = 0;
|
||||||
|
|
||||||
|
resetCompression() {
|
||||||
|
this.counter = 0;
|
||||||
|
this.compression = new Shorty();
|
||||||
|
this.conn.send('shorty');
|
||||||
|
}
|
||||||
|
|
||||||
send(data: any) {
|
send(data: any) {
|
||||||
let payload = JSON.stringify(data, serializer({
|
let payload = JSON.stringify(data, serializer({
|
||||||
showDisplayName: this.user?.hasPerm(PERM.PERM_VIEW_DISPLAYNAME),
|
showDisplayName: this.user?.hasPerm(PERM.PERM_VIEW_DISPLAYNAME),
|
||||||
}));
|
}));
|
||||||
if (this.compression) payload = this.compression.deflate(payload);
|
if (this.compression) {
|
||||||
|
if (this.counter > 1000) this.resetCompression();
|
||||||
|
payload = this.compression.deflate(payload);
|
||||||
|
this.counter++;
|
||||||
|
}
|
||||||
this.conn.send(payload);
|
this.conn.send(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,10 +424,7 @@ export function Connection(
|
|||||||
const disposables = [];
|
const disposables = [];
|
||||||
try {
|
try {
|
||||||
checker.call(h);
|
checker.call(h);
|
||||||
if (args.shorty) {
|
if (args.shorty) h.resetCompression();
|
||||||
h.compression = new Shorty();
|
|
||||||
conn.send('shorty');
|
|
||||||
}
|
|
||||||
if (h._prepare) await h._prepare(args);
|
if (h._prepare) await h._prepare(args);
|
||||||
if (h.prepare) await h.prepare(args);
|
if (h.prepare) await h.prepare(args);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||||
|
|||||||
Reference in new issue
Block a user