Skip to content

Commit

Permalink
fix: test exclude performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Sep 24, 2024
1 parent 08abcbd commit 210eae9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/canyon-backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ model Coverage {
statementsCovered Int @map("statements_covered")
newlinesTotal Int @map("newlines_total")
newlinesCovered Int @map("newlines_covered")
summary String?
// 代码覆盖率详情
hit String
// 通用
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,15 @@ export class ConsumerCoverageService {
})();

const newcoverage = mergeCoverageMap(queueDataToBeConsumed.coverage, cov);
const sum: any = getSummaryByPath(
"",
genSummaryMapByCoverageMap(
await this.testExcludeService.invoke(
queueDataToBeConsumed.projectID,
newcoverage,
),
codechanges,
const summary = genSummaryMapByCoverageMap(
await this.testExcludeService.invoke(
queueDataToBeConsumed.projectID,
newcoverage,
),
codechanges,
);
const sum: any = getSummaryByPath("", summary);
const summaryZstd = await compressedData(JSON.stringify(summary));

const hit = await compressedData(JSON.stringify(newcoverage));
if (coverage) {
Expand All @@ -162,6 +161,7 @@ export class ConsumerCoverageService {
branchesTotal: sum.branches.total,
linesCovered: sum.lines.covered,
linesTotal: sum.lines.total,
summary: summaryZstd,
updatedAt: queueDataToBeConsumed.updatedAt,
compareTarget: queueDataToBeConsumed.compareTarget,
},
Expand All @@ -182,6 +182,7 @@ export class ConsumerCoverageService {
branchesTotal: sum.branches.total,
linesCovered: sum.lines.covered,
linesTotal: sum.lines.total,
summary: summaryZstd,
//以下都读的是queueDataToBeConsumed
// key: queueDataToBeConsumed.key,
branch: queueDataToBeConsumed.branch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class CoverageClientService {
newlinesCovered: 0,
newlinesTotal: 0,
hit: "",
summary: "",
coverage: coverageReport.coverage,
instrumentCwd: coverageReport.instrumentCwd,
createdAt: coverageReport.createdAt || new Date(),
Expand Down
41 changes: 33 additions & 8 deletions packages/canyon-backend/src/coverage/services/coverage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,45 @@ export class CoverageService {
if (coverages.length === 0) {
return [];
}
const coverageData = await this.getCoverageDataFromAdapter(
projectID,
sha,
reportID,
).then((r) => this.testExcludeService.invoke(coverages[0].projectID, r));

const codechanges = await this.prisma.codechange.findMany({
where: {
compareTarget: coverages[0].compareTarget,
sha: sha,
},
});
const covSummary = genSummaryMapByCoverageMap(coverageData, codechanges);
return Object.entries(covSummary).map(([key, value]) => {

let covSummary = await this.prisma.coverage
.findFirst({
where: removeNullKeys({
sha,
projectID,
reportID: reportID || null,
covType: reportID ? "agg" : "all",
}),
})
.then((cov) => {
if (cov && cov.summary) {
// zstd解压
return decompressedData(cov.summary).then((summary) => {
return JSON.parse(summary);
});
} else {
return null;
}
});

if (!covSummary) {
const coverageData = await this.getCoverageDataFromAdapter(
projectID,
sha,
reportID,
).then((r) => this.testExcludeService.invoke(coverages[0].projectID, r));

covSummary = genSummaryMapByCoverageMap(coverageData, codechanges);
}

return Object.entries(covSummary).map(([key, value]: any) => {
return {
path: key,
...value,
Expand Down Expand Up @@ -108,7 +134,6 @@ export class CoverageService {
});
}),
);
// console.log(filepath,'filepath')
const obj = {};
coverageJsonMaps.forEach((item) => {
if (hit[item.path]) {
Expand Down

0 comments on commit 210eae9

Please sign in to comment.