Skip to content

Commit

Permalink
chore: repo overall update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 20, 2024
1 parent e43e918 commit ca3beaf
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 64 deletions.
12 changes: 6 additions & 6 deletions packages/canyon-collect/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { PrismaService } from './prisma/prisma.service';
import { zstdDecompressedData } from './utils/zstd2';
import { coverageObj } from './apps/collect/models/coverage.model';
import { IstanbulHitMapSchema, IstanbulMapMapSchema } from './zod/istanbul.zod';
import { removeStartEndNull } from './utils/coverage';
import { compressedData } from './utils/zstd';
import { genSummaryMapByCoverageMap, mergeCoverageMap } from 'canyon-data';
// import { zstdDecompressedData } from './utils/zstd2';
// import { coverageObj } from './apps/collect/models/coverage.model';
// import { IstanbulHitMapSchema, IstanbulMapMapSchema } from './zod/istanbul.zod';
// import { removeStartEndNull } from './utils/coverage';
// import { compressedData } from './utils/zstd';
// import { genSummaryMapByCoverageMap, mergeCoverageMap } from 'canyon-data';
// import fs from 'node:fs';

@Controller()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ export class CoverageClientService {
const coverageObject =
typeof coverage === 'string' ? JSON.parse(coverage) : coverage;

const coverageDbMap = await decompressedData(coverageDb.map)
.then((r) => r.toString())
.then((r) => JSON.parse(r));

const coverageDbHit = await decompressedData(coverageDb.hit)
.then((r) => r.toString())
.then((r) => JSON.parse(r));
// console.log('oldcoverage', coverageMapCount111);
const coverageDbMap = await decompressedData(coverageDb.map);

const coverageDbHit = await decompressedData(coverageDb.hit);
// 流程需要改一下
// 1. 不反map
// 2. 在消费的时候再反map
Expand All @@ -62,7 +57,7 @@ export class CoverageClientService {

// update
// mergeCoveHit
const hitBuffer = await compressedData(JSON.stringify(mergeCoveHit));
const hitBuffer = await compressedData(mergeCoveHit);

// ********* 生成summary
// 生成summary
Expand Down Expand Up @@ -104,7 +99,7 @@ export class CoverageClientService {
...value,
}));

const summaryBuffer = await compressedData(JSON.stringify(summary));
const summaryBuffer = await compressedData(summary);

return this.prisma.coverage.updateMany({
where: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { PrismaService } from '../../../prisma/prisma.service';
import { Injectable } from '@nestjs/common';
import {
// IstanbulHitMapSchema,
IstanbulMapMapSchema,
} from '../../../zod/istanbul.zod';
import { compressedData, decompressedData } from '../../../utils/zstd';
import { IstanbulMapMapSchema } from '../../../zod/istanbul.zod';
import { compressedData } from '../../../utils/zstd';
import {
formatReportObject,
regularData,
Expand Down Expand Up @@ -46,8 +43,7 @@ export class CoverageMapClientService {
removeStartEndNull(formatedCoverage),
);

const formatCoverageStr = JSON.stringify(formatCoverageMap);
const compressedFormatCoverageStr = await compressedData(formatCoverageStr);
const compressedFormatCoverageStr = await compressedData(formatCoverageMap);

// ******************************************************
// ******************************************************
Expand Down
11 changes: 4 additions & 7 deletions packages/canyon-collect/src/utils/zstd.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import * as zlib from 'node:zlib';

// 输入是一个对象,输出是一个 Buffer
export async function compressedData(input) {
const options = {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11, // 设置压缩质量
},
};

const compressed = zlib.brotliCompressSync(input, options);
return compressed;
return zlib.brotliCompressSync(JSON.stringify(input), options);
}

// 输入是一个 Buffer,输出是一个对象
export async function decompressedData(compressedData) {
if (compressedData.length === 0) {
return '{}';
}
const decompressed = zlib.brotliDecompressSync(compressedData);
return decompressed;
return JSON.parse(decompressed.toString());
}
6 changes: 0 additions & 6 deletions packages/canyon-collect/src/utils/zstd2.ts

This file was deleted.

Empty file added packages/canyon-data/index.ts
Empty file.
16 changes: 4 additions & 12 deletions packages/canyon-platform/app/api/cov/map/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
// export const dynamic = 'force-static'
import prisma from "@/lib/prisma";
import { compressedData, decompressedData } from "@/utils/zstd";
import { decompressedData } from "@/utils/zstd";
import { formatReportObject, remapCoverage } from "@/utils/coverage";
import { NextRequest } from "next/server";
// import { decompressedData } from "@/utils/zstd";

// import { compress, decompress } from "@mongodb-js/zstd";

// localhost:3000/api/cov/map?sha=0cacb37b236c9507004505662a0d6bfb018aaec4&project_id=490316875
export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
const projectID = searchParams.get("project_id");
Expand All @@ -20,12 +15,9 @@ export async function GET(request: NextRequest) {
},
});

const d = await decompressedData(data.map)
.then((r) => r.toString())
.then((r) => JSON.parse(r));
const c = await decompressedData(data.hit)
.then((r) => r.toString())
.then((r) => JSON.parse(r));
const d = await decompressedData(data.map);

const c = await decompressedData(data.hit);

const obj = {};

Expand Down
5 changes: 1 addition & 4 deletions packages/canyon-platform/app/api/cov/summary/map/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ export async function GET(request: NextRequest) {
});

// coverage.summary
const summary = await decompressedData(coverage.summary)
.then((r) => r.toString())
.then((r) => JSON.parse(r));
// return summary;
const summary = await decompressedData(coverage.summary);
return Response.json(summary);
}
14 changes: 2 additions & 12 deletions packages/canyon-platform/utils/zstd.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import * as zlib from "node:zlib";

export async function compressedData(input) {
const options = {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11, // 设置压缩质量
},
};

const compressed = zlib.brotliCompressSync(input, options);
return compressed;
}

// 输入是一个 Buffer,输出是一个对象
export async function decompressedData(compressedData) {
const decompressed = zlib.brotliDecompressSync(compressedData);
return decompressed;
return JSON.parse(decompressed.toString());
}

0 comments on commit ca3beaf

Please sign in to comment.