Skip to content

Commit

Permalink
Lazy-load pako when submitting rageshake (#2782)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose authored Nov 14, 2024
1 parent 84e172a commit 85d8e03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@types/jsdom": "^21.1.7",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.0.0",
"@types/pako": "^2.0.3",
"@types/qrcode": "^1.5.5",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
Expand Down
16 changes: 9 additions & 7 deletions src/settings/submit-rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ Please see LICENSE in the repository root for full details.
*/

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 {
ClientEvent,
Expand All @@ -23,11 +20,14 @@ import { Config } from "../config/Config";
import { ElementCallOpenTelemetry } from "../otel/otel";
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
const buf = new TextEncoder().encode(text);
// compress
return new Blob([pako.gzip(buf)]);
return new Blob([pakoGzip(buf)]);
};

/**
Expand Down Expand Up @@ -253,12 +253,14 @@ export function useSubmitRageshake(): {
const logs = await getLogsForReport();

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(
"file",
gzip(ElementCallOpenTelemetry.instance.rageshakeProcessor!.dump()),
await gzip(
ElementCallOpenTelemetry.instance.rageshakeProcessor!.dump(),
),
"traces.json.gz",
);
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3060,6 +3060,11 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz#56e2cc26c397c038fab0e3a917a12d5c5909e901"
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@*":
version "15.7.13"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.13.tgz#2af91918ee12d9d32914feb13f5326658461b451"
Expand Down

0 comments on commit 85d8e03

Please sign in to comment.