perf: 优化pipeline删除时,删除其他history

pull/148/head
xiaojunnuo 2024-08-05 12:57:13 +08:00
parent f78ae93eed
commit b4252033d5
4 changed files with 25 additions and 0 deletions

View File

@ -18,7 +18,9 @@ export interface IFileStore {
export class FileStore {
rootDir: string;
// pipelineId
scope: string;
// historyId
parent: string;
constructor(options?: FileStoreOptions) {
this.rootDir = fileUtils.getFileRootDir(options?.rootDir);

View File

@ -31,4 +31,8 @@ export class HistoryLogService extends BaseService<HistoryLogEntity> {
}
await this.repository.delete({ historyId: In(numbers) });
}
async deleteByPipelineId(id: number) {
await this.repository.delete({ pipelineId: id });
}
}

View File

@ -142,4 +142,21 @@ export class HistoryService extends BaseService<HistoryEntity> {
});
await this.logService.deleteByHistoryIds(ids);
}
async deleteByPipelineId(id: number) {
await this.repository.delete({
pipelineId: id,
});
try {
const fileStore = new FileStore({
rootDir: this.certdConfig.fileRootDir,
scope: id + '',
parent: '0',
});
fileStore.deleteByParent(id + '', '');
} catch (e) {
logger.error('删除文件失败', e);
}
}
}

View File

@ -198,6 +198,8 @@ export class PipelineService extends BaseService<PipelineEntity> {
// const storage = new DbStorage(pipeline.userId, this.storageService);
// await storage.remove(pipeline.id);
await super.delete([id]);
await this.historyService.deleteByPipelineId(id);
await this.historyLogService.deleteByPipelineId(id);
}
async clearTriggers(id: number) {