diff --git a/packages/canyon-backend/prisma/migrations/20240713143952_up/migration.sql b/packages/canyon-backend/prisma/migrations/20240713143952_up/migration.sql new file mode 100644 index 00000000..f93e019f --- /dev/null +++ b/packages/canyon-backend/prisma/migrations/20240713143952_up/migration.sql @@ -0,0 +1,39 @@ +/* + Warnings: + + - You are about to drop the `coveragedata` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `file_map` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `reckoning` table. If the table is not empty, all the data it contains will be lost. + - Added the required column `instrument_cwd` to the `project` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "project" ADD COLUMN "instrument_cwd" TEXT NOT NULL; + +-- DropTable +DROP TABLE "coveragedata"; + +-- DropTable +DROP TABLE "file_map"; + +-- DropTable +DROP TABLE "reckoning"; + +-- DropEnum +DROP TYPE "DimType"; + +-- CreateTable +CREATE TABLE "CovMap" ( + "id" TEXT NOT NULL, + "map_json_str_zstd" TEXT NOT NULL, + + CONSTRAINT "CovMap_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "CovHit" ( + "id" TEXT NOT NULL, + "map_json_str" TEXT NOT NULL, + + CONSTRAINT "CovHit_pkey" PRIMARY KEY ("id") +); diff --git a/packages/canyon-backend/prisma/schema.prisma b/packages/canyon-backend/prisma/schema.prisma index 5a234366..474c1d99 100755 --- a/packages/canyon-backend/prisma/schema.prisma +++ b/packages/canyon-backend/prisma/schema.prisma @@ -65,28 +65,14 @@ model Coverage { @@map("coverage") } -model Hit { - id String @id - hitJson String @map("hitjson") - - @@map("hit") +model CovMap { + id String @id + mapJsonStrZstd String @map("map_json_str_zstd") } -model FileMap { - // TODO 有个问题,每次来的时候,path可能会增加,这个时候,需要更新 - // id = projectID + sha + path - id String @id - mapJson String @map("map_json") - - @@map("file_map") -} - -model CoverageData { - id String @id @default(cuid()) - compresseddata String - createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(3) - - @@map("coveragedata") +model CovHit { + id String @id + mapJsonStr String @map("map_json_str") } model Project { diff --git a/packages/canyon-backend/src/coverage/services/common/coverage-data-adapter.service.ts b/packages/canyon-backend/src/coverage/services/common/coverage-data-adapter.service.ts index 5e06e1c9..95341a25 100755 --- a/packages/canyon-backend/src/coverage/services/common/coverage-data-adapter.service.ts +++ b/packages/canyon-backend/src/coverage/services/common/coverage-data-adapter.service.ts @@ -37,13 +37,11 @@ export class CoverageDataAdapterService { ); } retrieve(relationID) { - console.log(relationID,'relationID') return this.coverageDataModel .findOne({ _id: new mongoose.Types.ObjectId(relationID), }) .then((r) => { - console.log(r) return decompressedData(r.coverage) }) .then((r) => JSON.parse(r)); diff --git a/packages/canyon-backend/src/task/syns.service.ts b/packages/canyon-backend/src/task/syns.service.ts index a811a12d..196ae416 100644 --- a/packages/canyon-backend/src/task/syns.service.ts +++ b/packages/canyon-backend/src/task/syns.service.ts @@ -2,6 +2,7 @@ import {Injectable} from "@nestjs/common"; import {PrismaService} from "../prisma/prisma.service"; import {Timeout} from "@nestjs/schedule"; import {CoverageDataAdapterService} from "../coverage/services/common/coverage-data-adapter.service"; +import * as fs from "node:fs"; @Injectable() export class SynsService { @@ -13,10 +14,21 @@ export class SynsService { @Timeout(1) async mainTask() { + // const ids = await this.prisma.fileMap.findMany({ + // where:{ + // }, + // select:{ + // id:true + // } + // }) + // console.log([ + // ...new Set(ids.map(item=>item.id).map(item=>item.split('__')[2])) + // ].length) // 1.查出07-12 12:00以前的coverage数据 const ids = await this.prisma.coverage.findMany({ where:{ projectID:{ + contains:'61889', // equals:'clveyrs690000pufq6p74anzd', not:{ contains:'-ut' @@ -33,6 +45,7 @@ export class SynsService { covType:true } }); + console.log(ids.length) // 2.遍历coverage for (let i = 0; i < ids.length; i++) { console.log('ids',ids[i].id) @@ -63,59 +76,56 @@ export class SynsService { const coverage = coverageData; - const fileMapTasks = Object.entries(coverage).map( - async (coverageEntries) => { - const [path, fileCoverage]: any = coverageEntries; - await this.prisma.fileMap - .create({ - data: { - id: `__${projectID}__${sha}__${path.replaceAll('~/','')}__`, - mapJson: JSON.stringify({ - fnMap: fileCoverage.fnMap, - statementMap: fileCoverage.statementMap, - branchMap: fileCoverage.branchMap, - }), - }, - }) - .then((res) => { - return res; - }) - .catch(() => { - return true; - }); - }, - ); - const time2 = new Date().getTime(); - await Promise.all(fileMapTasks); - - console.log('fileMapTasks', new Date().getTime() - time2); + await this.prisma.covMap + .create({ + data: { + id: `__${projectID}__${sha}__`, + mapJsonStrZstd: JSON.stringify(Object.entries(coverage).reduce((previousValue, currentValue:any)=>{ + previousValue[currentValue[0]] = { + f: currentValue[1].fnMap, + b: currentValue[1].branchMap, + s: currentValue[1].statementMap, + } + return previousValue + },{})), + }, + }) + .then((res) => { + return res; + }) + .catch(() => { + return true; + }); + + const time3 = new Date().getTime(); - const hitTasks = Object.entries(coverage).map( - async (coverageEntries) => { - const [path, fileCoverage]: any = coverageEntries; - await this.prisma.hit - .create({ - data: { - id: `__${ids[i].id}__${path.replaceAll('~/','')}__`, - hitJson: JSON.stringify({ - f: fileCoverage.f, - b: fileCoverage.b, - s: fileCoverage.s, - }), - }, - }) - .then((res) => { - return res; - }) - .catch((e) => { - return true; - }); - }, - ); - await Promise.all(hitTasks); + + + await this.prisma.covHit + .create({ + data: { + id: `__${ids[i].id}__`, + mapJsonStr: JSON.stringify(Object.entries(coverage).reduce((previousValue, currentValue:any)=>{ + previousValue[currentValue[0]] = { + f: currentValue[1].f, + b: currentValue[1].b, + s: currentValue[1].s, + } + return previousValue + },{})), + }, + }) + .then((res) => { + return res; + }) + .catch((e) => { + return true; + }); + + console.log('hitTasks', new Date().getTime() - time3); } } else {