-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Allen Zhang (张涛)
committed
Apr 9, 2024
1 parent
cd9fa97
commit c8f32d7
Showing
8 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/canyon-backend/src/coverage/coveragedisk.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; | ||
|
||
@Entity('coveragedisk') | ||
export class CoveragediskEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
pid: string; | ||
|
||
@Column() | ||
projectID: string; | ||
|
||
@Column() | ||
sha: string; | ||
|
||
@Column() | ||
data: string; | ||
|
||
@Column() | ||
createdAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/canyon-backend/src/coverage/services/menu.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { CoveragediskEntity } from '../coveragedisk.entity'; | ||
import { Repository } from 'typeorm'; | ||
// import { pushQueue } from '../../queues/coverage'; | ||
import * as process from 'node:process'; | ||
import { mergeCoverageMap } from '@canyon/data'; | ||
|
||
@Injectable() | ||
export class MenuService { | ||
constructor( | ||
@InjectRepository(CoveragediskEntity) | ||
private readonly menuRepository: Repository<CoveragediskEntity>, | ||
) {} | ||
async create() { | ||
const s = await this.menuRepository.find(); | ||
console.log(s); | ||
return this.menuRepository.insert({ | ||
projectID: 'test', | ||
sha: 'test', | ||
data: 'test', | ||
}); | ||
} | ||
// Add CRUD operations you intend to use here | ||
async pushQueue(data) { | ||
return this.menuRepository.insert({ | ||
pid: String(process.pid), | ||
projectID: data.projectID, | ||
sha: data.sha, | ||
data: JSON.stringify(data), | ||
createdAt: new Date(), | ||
}); | ||
} | ||
async getQueueWithSameShaAndProjectID() { | ||
const old = await this.menuRepository.findOne({ | ||
where: { | ||
pid: String(process.pid), | ||
}, | ||
order: { | ||
createdAt: 'ASC', | ||
}, | ||
select: { | ||
pid: true, | ||
projectID: true, | ||
sha: true, | ||
data: true, | ||
}, | ||
}); | ||
if (!old) { | ||
return false; | ||
} | ||
const arr = await this.menuRepository.find({ | ||
where: { | ||
projectID: old.projectID, | ||
sha: old.sha, | ||
pid: String(process.pid), | ||
}, | ||
select: { | ||
id: true, | ||
}, | ||
}); | ||
let cov = {}; | ||
for (let i = 0; i < arr.length; i++) { | ||
const toBeConsumedQueues = await this.menuRepository.findOne({ | ||
where: { id: arr[i].id, pid: String(process.pid) }, | ||
}); | ||
// 聚合 | ||
cov = mergeCoverageMap(cov, JSON.parse(toBeConsumedQueues.data).coverage); | ||
await this.menuRepository.delete({ id: arr[i].id }); | ||
} | ||
return { | ||
...JSON.parse(old.data), | ||
coverage: cov, | ||
}; | ||
} | ||
} |