Lazy-load pako when submitting rageshake (#2782)

This commit is contained in:
Quentin Gliech 2024-11-14 14:00:01 +01:00 committed by GitHub
parent 84e172a2ba
commit 85d8e036d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 7 deletions

View File

@ -53,6 +53,7 @@
"@types/jsdom": "^21.1.7", "@types/jsdom": "^21.1.7",
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@types/node": "^20.0.0", "@types/node": "^20.0.0",
"@types/pako": "^2.0.3",
"@types/qrcode": "^1.5.5", "@types/qrcode": "^1.5.5",
"@types/react-dom": "^18.3.0", "@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3", "@types/react-router-dom": "^5.3.3",

View File

@ -6,9 +6,6 @@ Please see LICENSE in the repository root for full details.
*/ */
import { ComponentProps, useCallback, useEffect, useState } from "react"; import { ComponentProps, useCallback, useEffect, useState } from "react";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import pako from "pako";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { import {
ClientEvent, ClientEvent,
@ -23,11 +20,14 @@ import { Config } from "../config/Config";
import { ElementCallOpenTelemetry } from "../otel/otel"; import { ElementCallOpenTelemetry } from "../otel/otel";
import { RageshakeRequestModal } from "../room/RageshakeRequestModal"; import { RageshakeRequestModal } from "../room/RageshakeRequestModal";
const gzip = (text: string): Blob => { const gzip = async (text: string): Promise<Blob> => {
// pako is relatively large (200KB), so we only import it when needed
const { gzip: pakoGzip } = await import("pako");
// encode as UTF-8 // encode as UTF-8
const buf = new TextEncoder().encode(text); const buf = new TextEncoder().encode(text);
// compress // compress
return new Blob([pako.gzip(buf)]); return new Blob([pakoGzip(buf)]);
}; };
/** /**
@ -253,12 +253,14 @@ export function useSubmitRageshake(): {
const logs = await getLogsForReport(); const logs = await getLogsForReport();
for (const entry of logs) { for (const entry of logs) {
body.append("compressed-log", gzip(entry.lines), entry.id); body.append("compressed-log", await gzip(entry.lines), entry.id);
} }
body.append( body.append(
"file", "file",
gzip(ElementCallOpenTelemetry.instance.rageshakeProcessor!.dump()), await gzip(
ElementCallOpenTelemetry.instance.rageshakeProcessor!.dump(),
),
"traces.json.gz", "traces.json.gz",
); );
} }

View File

@ -3060,6 +3060,11 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz#56e2cc26c397c038fab0e3a917a12d5c5909e901" resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz#56e2cc26c397c038fab0e3a917a12d5c5909e901"
integrity sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA== integrity sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==
"@types/pako@^2.0.3":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/pako/-/pako-2.0.3.tgz#b6993334f3af27c158f3fe0dfeeba987c578afb1"
integrity sha512-bq0hMV9opAcrmE0Byyo0fY3Ew4tgOevJmQ9grUhpXQhYfyLJ1Kqg3P33JT5fdbT2AjeAjR51zqqVjAL/HMkx7Q==
"@types/prop-types@*": "@types/prop-types@*":
version "15.7.13" version "15.7.13"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.13.tgz#2af91918ee12d9d32914feb13f5326658461b451" resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.13.tgz#2af91918ee12d9d32914feb13f5326658461b451"