Skip to content

Commit

Permalink
feat: migrate projectID to repoID
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Dec 30, 2024
1 parent c0d9207 commit 70fc7cf
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/canyon-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"do-build": "prisma generate && nest build",
"start": "nest start",
"dev-backend": "nest start --watch",
"preinstall": "prisma generate",
"preinstall": "prisma generate && nest build",
"format": "prettier --write '**/*.{js,ts,jsx,tsx}'"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Injectable } from "@nestjs/common";
import { PrismaService } from "src/prisma/prisma.service";
// import { decompressedData } from "canyon-map";
// import { convertDataFromCoverageMapDatabase } from "canyon-map";
import {
remapCoverageWithInstrumentCwd,
convertDataFromCoverageMapDatabase,
Expand Down Expand Up @@ -35,29 +33,14 @@ export class CoverageFinalService {
},
hit?: { [key: string]: object },
) {
const coverages = await this.prisma.coverage.findMany({
where: {
sha,
projectID,
reportID: reportID
? {
in: reportID.split(","),
}
: undefined,
covType: reportID ? "agg" : "all",
},
});

let hitBox = {};
for (let i = 0; i < coverages.length; i++) {
hitBox = mergeCoverageMap(
hitBox,
await decompressedData(coverages[i].hit),
);
}

// 如果外部传入了hit,就不再从数据库中获取hit
hit = hit || hitBox;
hit =
hit ||
(await this.getHitByProjectIDShaReportID({
projectID,
sha,
reportID,
}));

// 无论是外部hit,还是查询到的hit,都为空对象,直接返回空对象
if (Object.keys(hit).length === 0) {
Expand All @@ -67,7 +50,7 @@ export class CoverageFinalService {
const coverageMaps = await this.prisma.coverageMap.findMany({
where: {
sha,
projectID,
repoID: projectID.split("-")[1],
path: filepath,
},
});
Expand All @@ -77,15 +60,42 @@ export class CoverageFinalService {
return {};
}

const { map, instrumentCwd } =
await convertDataFromCoverageMapDatabase(coverageMaps);
// 等会删掉
const { map, instrumentCwd } = await convertDataFromCoverageMapDatabase(
coverageMaps.map((i) => ({
...i,
projectID: "11",
})),
);

const reMapMap = await remapCoverageWithInstrumentCwd(
resetCoverageDataMap(map),
instrumentCwd,
);

// console.log("reMapMap", reMapMap);
return reorganizeCompleteCoverageObjects(reMapMap, hit);
}

private async getHitByProjectIDShaReportID({ projectID, sha, reportID }) {
const coverages = await this.prisma.coverage.findMany({
where: {
sha,
projectID,
reportID: reportID
? {
in: reportID.split(","),
}
: undefined,
covType: reportID ? "agg" : "all",
},
});

let hitBox = {};
for (let i = 0; i < coverages.length; i++) {
hitBox = mergeCoverageMap(
hitBox,
await decompressedData(coverages[i].hit),
);
}
return hitBox;
}
}
2 changes: 1 addition & 1 deletion packages/canyon-map/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canyon-map",
"version": "2.0.0-beta.8",
"version": "2.0.0-beta.9",
"description": "",
"type": "module",
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions packages/canyon-map/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {decompressedData} from "./compress.ts";

export const convertDataFromCoverageMapDatabase = async (
coverageMaps: {
projectID: string;
sha: string;
// projectID: string;
// sha: string;
// path: string;
instrumentCwd: string;
map: Buffer;
Expand Down
6 changes: 3 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ model Coverage {

model CoverageMap {
id String @id @default(cuid())
projectID String @map("project_id")
repoID String @map("repo_id")
sha String @map("sha")
path String
map Bytes
Expand All @@ -83,7 +83,7 @@ model CoverageMap {
// 再添加一个path索引
@@index(fields: [path])
@@index([projectID, sha]) // 联合索引
@@index([repoID, sha]) // 联合索引
@@map("canyon3_coverage_map")
}

Expand All @@ -106,7 +106,7 @@ model Project {

model Codechange {
id String @id @default(cuid())
projectID String @map("project_id")
repoID String @map("repo_id")
compareTarget String @map("compare_target")
sha String @map("sha")
path String
Expand Down

0 comments on commit 70fc7cf

Please sign in to comment.