core: reset compression regularly

This commit is contained in:
undefined committed 2024-01-30 17:55:15 +08:00
1 parent d99e11e3e2
commit 54ce1ca180
1 file changed
+13 -5
+13 -5
View File
@@ -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