From 07e5793d1f065232cf90e1df2a365d7706a3e758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allen=20Zhang=20=28=E5=BC=A0=E6=B6=9B=29?= Date: Thu, 31 Oct 2024 14:05:17 +0800 Subject: [PATCH] feat: update --- .../core/consumer-coverage.service.ts | 3 +- packages/canyon-platform/src/collect.ts | 78 +++++++++---------- packages/canyon-platform/src/main.tsx | 2 +- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/packages/canyon-backend/src/coverage/services/core/consumer-coverage.service.ts b/packages/canyon-backend/src/coverage/services/core/consumer-coverage.service.ts index 4f1182e9..e41ad95b 100644 --- a/packages/canyon-backend/src/coverage/services/core/consumer-coverage.service.ts +++ b/packages/canyon-backend/src/coverage/services/core/consumer-coverage.service.ts @@ -186,7 +186,8 @@ export class ConsumerCoverageService { const sum: any = getSummaryByPath("", summary); const summaryZstd = await compressedData(JSON.stringify(summary)); - const hit = await compressedData(JSON.stringify(newcoverage)); + // 实际存储不能用全量数据,大10倍 + const hit = await compressedData(JSON.stringify(hit1)); if (coverage) { await this.prisma.coverage.update({ where: { diff --git a/packages/canyon-platform/src/collect.ts b/packages/canyon-platform/src/collect.ts index 96f0e3e3..a14bb33f 100644 --- a/packages/canyon-platform/src/collect.ts +++ b/packages/canyon-platform/src/collect.ts @@ -1,39 +1,39 @@ -// 要收集的数据 -// const dataToSend = JSON.stringify(); -// window.__canyon__ = {} -// window.__coverage__ = {} -// 数据收集函数 -// @ts-ignore -if (window.__canyon__ && window.__coverage__) { - function collectData(t) { - navigator.sendBeacon( - "/api/coverage/collect", - JSON.stringify({ - // @ts-ignore - ...window.__canyon__, - // @ts-ignore - coverage: window.__coverage__, - reportID: t, - }), - ); - } - - // beforeunload 事件:当用户即将离开页面时触发 - window.addEventListener("beforeunload", () => { - collectData("beforeunload"); - }); - - // unload 事件:在页面完全卸载前触发 - window.addEventListener("unload", () => { - collectData("unload"); - }); - - // visibilitychange 事件:当页面变为不可见(如切换到其他标签页)时触发 - document.addEventListener("visibilitychange", () => { - if (document.visibilityState === "hidden") { - collectData("visibilitychange"); - } - }); -} else { - console.log("no canyon no coverage"); -} +// // 要收集的数据 +// // const dataToSend = JSON.stringify(); +// // window.__canyon__ = {} +// // window.__coverage__ = {} +// // 数据收集函数 +// // @ts-ignore +// if (window.__canyon__ && window.__coverage__) { +// function collectData(t) { +// navigator.sendBeacon( +// "/api/coverage/collect", +// JSON.stringify({ +// // @ts-ignore +// ...window.__canyon__, +// // @ts-ignore +// coverage: window.__coverage__, +// reportID: t, +// }), +// ); +// } +// +// // beforeunload 事件:当用户即将离开页面时触发 +// window.addEventListener("beforeunload", () => { +// collectData("beforeunload"); +// }); +// +// // unload 事件:在页面完全卸载前触发 +// window.addEventListener("unload", () => { +// collectData("unload"); +// }); +// +// // visibilitychange 事件:当页面变为不可见(如切换到其他标签页)时触发 +// document.addEventListener("visibilitychange", () => { +// if (document.visibilityState === "hidden") { +// collectData("visibilitychange"); +// } +// }); +// } else { +// console.log("no canyon no coverage"); +// } diff --git a/packages/canyon-platform/src/main.tsx b/packages/canyon-platform/src/main.tsx index ff78d2c8..7998bb59 100644 --- a/packages/canyon-platform/src/main.tsx +++ b/packages/canyon-platform/src/main.tsx @@ -3,7 +3,7 @@ import "./useWorker.ts"; import "./i18n.ts"; import "antd/dist/reset.css"; import "./index.css"; -import "./collect.ts"; +// import "./collect.ts"; import { ApolloClient,