From 87efc91d42b4b71b69415720042030ab20db9210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allen=20Zhang=20=28=E5=BC=A0=E6=B6=9B=29?= Date: Thu, 18 Jul 2024 22:38:39 +0800 Subject: [PATCH] feat: update --- .../src/coverage/coverage.controller.ts | 6 +- .../src/coverage/services/coverage.service.ts | 56 ++++++++++++++----- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/packages/canyon-backend/src/coverage/coverage.controller.ts b/packages/canyon-backend/src/coverage/coverage.controller.ts index 26a4e3e3..108ed189 100755 --- a/packages/canyon-backend/src/coverage/coverage.controller.ts +++ b/packages/canyon-backend/src/coverage/coverage.controller.ts @@ -14,7 +14,7 @@ import { CoverageService } from './services/coverage.service'; import { RetrieveCoverageTreeSummaryService } from './services/retrieve-coverage-tree-summary.service'; import { PrismaService } from '../prisma/prisma.service'; import { ConsumerCoverageService } from './services/core/consumer-coverage.service'; -import {CoverageReportsService} from "./services/coverage-reports.service"; +import { CoverageReportsService } from './services/coverage-reports.service'; @Controller() export class CoverageController { @@ -64,8 +64,8 @@ export class CoverageController { @Get('api/coverage/reports') async coverageReports(@Query() query): Promise { - const { bu, start,end } = query; - return this.coverageReportsService.invoke({bu, start,end }) + const { bu, start, end } = query; + return this.coverageReportsService.invoke({ bu, start, end }); } // 获取概览,重要!!!!! diff --git a/packages/canyon-backend/src/coverage/services/coverage.service.ts b/packages/canyon-backend/src/coverage/services/coverage.service.ts index 55cc77d8..6d9e67f9 100755 --- a/packages/canyon-backend/src/coverage/services/coverage.service.ts +++ b/packages/canyon-backend/src/coverage/services/coverage.service.ts @@ -82,6 +82,47 @@ export class CoverageService { reportID: reportID === '' ? undefined : reportID, }, }); + const promise = filepath + ? this.prisma.covMapTest + .findMany({ + where: removeNullKeys({ + projectID, + sha, + path: filepath, + }), + select: { + path: true, + mapJsonStr: true, + }, + }) + .then((res) => { + return res.reduce((acc, cur) => { + acc[cur.path] = JSON.parse(cur.mapJsonStr); + return acc; + }, {}); + }) + : this.prisma.covMapTest + .findMany({ + where: removeNullKeys({ + projectID, + sha, + path: filepath, + }), + select: { + path: true, + mapJsonStatementMapStartLine: true, + }, + }) + .then((res) => { + return res.reduce((acc, cur) => { + acc[cur.path] = { + statementMap: JSON.parse( + cur.mapJsonStatementMapStartLine || '{}', + ), + }; + return acc; + }, {}); + }); const maps = [ this.prisma.covHit .findFirst({ @@ -92,20 +133,7 @@ export class CoverageService { .then((res) => { return JSON.parse(res.mapJsonStr); }), - this.prisma.covMapTest - .findMany({ - where: removeNullKeys({ - projectID, - sha, - path: filepath, - }), - }) - .then((res) => { - return res.reduce((acc, cur) => { - acc[cur.path] = JSON.parse(cur.mapJsonStr); - return acc; - }, {}); - }), + promise, ]; const [hit, map] = await Promise.all(maps);