Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Jul 13, 2024
1 parent 9d4cbf6 commit f8e2c4f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -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")
);
26 changes: 6 additions & 20 deletions packages/canyon-backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
108 changes: 59 additions & 49 deletions packages/canyon-backend/src/task/syns.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f8e2c4f

Please sign in to comment.