From 46357d519398a47111501f6c6f0755cc3d900c3d Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Tue, 5 Dec 2023 16:06:47 +0800 Subject: [PATCH] fix: agg bug --- .../20231205070141_update/migration.sql | 8 +++ packages/canyon-backend/prisma/schema.prisma | 2 + .../services/project-overview.service.ts | 32 ++++++++---- .../services/aggregation-coverage.service.ts | 49 +++++++++---------- 4 files changed, 57 insertions(+), 34 deletions(-) create mode 100644 packages/canyon-backend/prisma/migrations/20231205070141_update/migration.sql diff --git a/packages/canyon-backend/prisma/migrations/20231205070141_update/migration.sql b/packages/canyon-backend/prisma/migrations/20231205070141_update/migration.sql new file mode 100644 index 00000000..eceec0c9 --- /dev/null +++ b/packages/canyon-backend/prisma/migrations/20231205070141_update/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - Added the required column `cov_type` to the `summary` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "summary" ADD COLUMN "cov_type" TEXT NOT NULL; diff --git a/packages/canyon-backend/prisma/schema.prisma b/packages/canyon-backend/prisma/schema.prisma index c0c165f0..b98954df 100755 --- a/packages/canyon-backend/prisma/schema.prisma +++ b/packages/canyon-backend/prisma/schema.prisma @@ -57,6 +57,8 @@ model Summary { metricType String @map("metric_type") + covType String @map("cov_type") + reportID String @map("report_id") commitSha String @map("commit_sha") diff --git a/packages/canyon-backend/src/coverage/services/project-overview.service.ts b/packages/canyon-backend/src/coverage/services/project-overview.service.ts index d2b54a7e..83beb36a 100644 --- a/packages/canyon-backend/src/coverage/services/project-overview.service.ts +++ b/packages/canyon-backend/src/coverage/services/project-overview.service.ts @@ -74,13 +74,17 @@ export class ProjectOverviewService { newlines: calculateCoverageOverviewByConditionFilter( summarys.filter( (item) => - item.commitSha === commitSha && item.reportID === report.reportID, + item.commitSha === commitSha && + item.reportID === report.reportID && + 'agg' === item.covType, ), ).newlines.pct, statements: calculateCoverageOverviewByConditionFilter( summarys.filter( (item) => - item.commitSha === commitSha && item.reportID === report.reportID, + item.commitSha === commitSha && + item.reportID === report.reportID && + 'agg' === item.covType, ), ).statements.pct, }; @@ -88,10 +92,16 @@ export class ProjectOverviewService { if (!acc[commitSha]) { acc[commitSha] = { statements: calculateCoverageOverviewByConditionFilter( - summarys.filter((item) => item.commitSha === commitSha), + //❌ + summarys.filter( + (item) => item.commitSha === commitSha && 'all' === item.covType, + ), ).statements.pct, newlines: calculateCoverageOverviewByConditionFilter( - summarys.filter((item) => item.commitSha === commitSha), + //❌ + summarys.filter( + (item) => item.commitSha === commitSha && 'all' === item.covType, + ), ).newlines.pct, commitSha, compareTarget: report.compareTarget, @@ -143,7 +153,9 @@ export class ProjectOverviewService { value: String( calculateCoverageOverviewByConditionFilter( summarys.filter( - (item) => item.reportID === aggCovTypeCoverages[0].reportID, + (item) => + item.reportID === aggCovTypeCoverages[0].reportID && + 'agg' === item.covType, ), ).statements.pct, ), @@ -154,15 +166,17 @@ export class ProjectOverviewService { return { commitSha: item.commitSha, statements: calculateCoverageOverviewByConditionFilter( + //❌ summarys.filter( - ({ commitSha: curCommitSha }) => - curCommitSha === item.commitSha, + ({ commitSha: curCommitSha, covType }) => + curCommitSha === item.commitSha && 'all' === covType, ), ).statements.pct, newlines: calculateCoverageOverviewByConditionFilter( + //❌ summarys.filter( - ({ commitSha: curCommitSha }) => - curCommitSha === item.commitSha, + ({ commitSha: curCommitSha, covType }) => + curCommitSha === item.commitSha && 'all' === covType, ), ).newlines.pct, }; diff --git a/packages/canyon-backend/src/tasks/services/aggregation-coverage.service.ts b/packages/canyon-backend/src/tasks/services/aggregation-coverage.service.ts index 7d9d7ed1..8f983264 100644 --- a/packages/canyon-backend/src/tasks/services/aggregation-coverage.service.ts +++ b/packages/canyon-backend/src/tasks/services/aggregation-coverage.service.ts @@ -59,34 +59,33 @@ export class AggregationCoverageService { }, }); - // 只有是agg的时候要删除就的agg的summary - if (covType === 'agg') { - await prisma.summary.deleteMany({ - where: { + // 删除老的 + await prisma.summary.deleteMany({ + where: removeNullKeys({ + reportID: covType === 'agg' ? reportID : null, + commitSha, + covType: covType, + }), + }); + + // 生成覆盖率数据 + const coverageSummaryMap = genSummaryMapByCoverageMap(mainCov, codechanges); + + const allSummary = getSummaryByPath('~', coverageSummaryMap); + for (const allSummaryKey in allSummary) { + // 落库数据 + const { total, skipped, covered } = allSummary[allSummaryKey] as any; + await prisma.summary.create({ + data: { reportID: reportID, + metricType: allSummaryKey, + commitSha: commitSha, + total, + skipped, + covered, + covType: covType, }, }); - - const coverageSummaryMap = genSummaryMapByCoverageMap( - mainCov, - codechanges, - ); - - const allSummary = getSummaryByPath('~', coverageSummaryMap); - for (const allSummaryKey in allSummary) { - // 落库数据 - const { total, skipped, covered } = allSummary[allSummaryKey] as any; - await prisma.summary.create({ - data: { - reportID: reportID, - metricType: allSummaryKey, - commitSha: commitSha, - total, - skipped, - covered, - }, - }); - } } await prisma.coverage.create({