mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
perf: 优化流水线列表页面、详情页面性能,精简返回数据
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
import { ALL, Body, Controller, Get, Inject, Post, Provide, Query } from '@midwayjs/core';
|
||||
import { CommonException, Constants, CrudController, PermissionException } from '@certd/lib-server';
|
||||
import { PipelineEntity } from '../../../modules/pipeline/entity/pipeline.js';
|
||||
import { HistoryService } from '../../../modules/pipeline/service/history-service.js';
|
||||
import { HistoryLogService } from '../../../modules/pipeline/service/history-log-service.js';
|
||||
import { HistoryEntity } from '../../../modules/pipeline/entity/history.js';
|
||||
import { HistoryLogEntity } from '../../../modules/pipeline/entity/history-log.js';
|
||||
import { PipelineService } from '../../../modules/pipeline/service/pipeline-service.js';
|
||||
import * as fs from 'fs';
|
||||
import { logger } from '@certd/basic';
|
||||
import { AuthService } from '../../../modules/sys/authority/service/auth-service.js';
|
||||
import { SysSettingsService } from '@certd/lib-server';
|
||||
import { In } from 'typeorm';
|
||||
import { ALL, Body, Controller, Get, Inject, Post, Provide, Query } from "@midwayjs/core";
|
||||
import { CommonException, Constants, CrudController, PermissionException, SysSettingsService } from "@certd/lib-server";
|
||||
import { PipelineEntity } from "../../../modules/pipeline/entity/pipeline.js";
|
||||
import { HistoryService } from "../../../modules/pipeline/service/history-service.js";
|
||||
import { HistoryLogService } from "../../../modules/pipeline/service/history-log-service.js";
|
||||
import { HistoryEntity } from "../../../modules/pipeline/entity/history.js";
|
||||
import { HistoryLogEntity } from "../../../modules/pipeline/entity/history-log.js";
|
||||
import { PipelineService } from "../../../modules/pipeline/service/pipeline-service.js";
|
||||
import * as fs from "fs";
|
||||
import { logger } from "@certd/basic";
|
||||
import { AuthService } from "../../../modules/sys/authority/service/auth-service.js";
|
||||
import { In } from "typeorm";
|
||||
|
||||
/**
|
||||
* 证书
|
||||
@@ -88,11 +87,30 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
const buildQuery = qb => {
|
||||
qb.limit(20);
|
||||
};
|
||||
const withDetail = body.withDetail;
|
||||
delete body.withDetail;
|
||||
let select:any = null
|
||||
if (!withDetail) {
|
||||
select = {
|
||||
pipeline: true, // 后面这里改成false
|
||||
id: true,
|
||||
userId: true,
|
||||
pipelineId: true,
|
||||
status: true,
|
||||
// startTime: true,
|
||||
triggerType: true,
|
||||
endTime: true,
|
||||
createTime: true,
|
||||
updateTime: true
|
||||
};
|
||||
}
|
||||
const listRet = await this.getService().list({
|
||||
query: body,
|
||||
sort: { prop: 'id', asc: false },
|
||||
buildQuery,
|
||||
select
|
||||
});
|
||||
|
||||
for (const item of listRet) {
|
||||
if (!item.pipeline) {
|
||||
continue;
|
||||
@@ -100,7 +118,13 @@ export class HistoryController extends CrudController<HistoryService> {
|
||||
const json = JSON.parse(item.pipeline);
|
||||
delete json.stages;
|
||||
item.pipeline = json;
|
||||
|
||||
//@ts-ignore
|
||||
item.version = json.version;
|
||||
item.status = json.status.result
|
||||
delete item.pipeline;
|
||||
}
|
||||
|
||||
return this.ok(listRet);
|
||||
}
|
||||
|
||||
|
||||
+22
-23
@@ -1,22 +1,21 @@
|
||||
import {IServiceGetter} from "@certd/pipeline";
|
||||
import {Inject, Provide, Scope, ScopeEnum} from "@midwayjs/core";
|
||||
import {AccessGetter, AccessService} from "@certd/lib-server";
|
||||
import {CnameProxyService} from "./cname-proxy-service.js";
|
||||
import {NotificationGetter} from "./notification-getter.js";
|
||||
import {NotificationService} from "../notification-service.js";
|
||||
import {CnameRecordService} from "../../../cname/service/cname-record-service.js";
|
||||
import {SubDomainsGetter} from './sub-domain-getter.js'
|
||||
import {DomainVerifierGetter} from "./domain-verifier-getter.js";
|
||||
import {Context} from "@midwayjs/koa";
|
||||
import {DomainService} from "../../../cert/service/domain-service.js";
|
||||
import {SubDomainService} from "../sub-domain-service.js";
|
||||
import { IServiceGetter } from "@certd/pipeline";
|
||||
import { ApplicationContext, IMidwayContainer, Provide, Scope, ScopeEnum } from "@midwayjs/core";
|
||||
import { AccessGetter, AccessService } from "@certd/lib-server";
|
||||
import { CnameProxyService } from "./cname-proxy-service.js";
|
||||
import { NotificationGetter } from "./notification-getter.js";
|
||||
import { NotificationService } from "../notification-service.js";
|
||||
import { CnameRecordService } from "../../../cname/service/cname-record-service.js";
|
||||
import { SubDomainsGetter } from "./sub-domain-getter.js";
|
||||
import { DomainVerifierGetter } from "./domain-verifier-getter.js";
|
||||
import { DomainService } from "../../../cert/service/domain-service.js";
|
||||
import { SubDomainService } from "../sub-domain-service.js";
|
||||
|
||||
export class TaskServiceGetter implements IServiceGetter{
|
||||
private userId: number;
|
||||
private ctx : Context;
|
||||
constructor(userId:number,ctx:Context) {
|
||||
private appCtx : IMidwayContainer;
|
||||
constructor(userId:number,appCtx:IMidwayContainer) {
|
||||
this.userId = userId;
|
||||
this.ctx = ctx
|
||||
this.appCtx = appCtx
|
||||
}
|
||||
async get<T>(serviceName: string): Promise<T> {
|
||||
|
||||
@@ -36,27 +35,27 @@ export class TaskServiceGetter implements IServiceGetter{
|
||||
}
|
||||
|
||||
async getSubDomainsGetter(): Promise<SubDomainsGetter> {
|
||||
const subDomainsService:SubDomainService = await this.ctx.requestContext.getAsync("subDomainService")
|
||||
const subDomainsService:SubDomainService = await this.appCtx.getAsync("subDomainService")
|
||||
return new SubDomainsGetter(this.userId, subDomainsService)
|
||||
}
|
||||
|
||||
async getAccessService(): Promise<AccessGetter> {
|
||||
const accessService:AccessService = await this.ctx.requestContext.getAsync("accessService")
|
||||
const accessService:AccessService = await this.appCtx.getAsync("accessService")
|
||||
return new AccessGetter(this.userId, accessService.getById.bind(accessService));
|
||||
}
|
||||
|
||||
async getCnameProxyService(): Promise<CnameProxyService> {
|
||||
const cnameRecordService:CnameRecordService = await this.ctx.requestContext.getAsync("cnameRecordService")
|
||||
const cnameRecordService:CnameRecordService = await this.appCtx.getAsync("cnameRecordService")
|
||||
return new CnameProxyService(this.userId, cnameRecordService.getWithAccessByDomain.bind(cnameRecordService));
|
||||
}
|
||||
|
||||
async getNotificationService(): Promise<NotificationGetter> {
|
||||
const notificationService:NotificationService = await this.ctx.requestContext.getAsync("notificationService")
|
||||
const notificationService:NotificationService = await this.appCtx.getAsync("notificationService")
|
||||
return new NotificationGetter(this.userId, notificationService);
|
||||
}
|
||||
|
||||
async getDomainVerifierGetter(): Promise<DomainVerifierGetter> {
|
||||
const domainService:DomainService = await this.ctx.requestContext.getAsync("domainService")
|
||||
const domainService:DomainService = await this.appCtx.getAsync("domainService")
|
||||
return new DomainVerifierGetter(this.userId, domainService);
|
||||
}
|
||||
}
|
||||
@@ -67,12 +66,12 @@ export type TaskServiceCreateReq = {
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Request, { allowDowngrade: true })
|
||||
export class TaskServiceBuilder {
|
||||
@Inject()
|
||||
ctx: Context;
|
||||
@ApplicationContext()
|
||||
appCtx: IMidwayContainer;
|
||||
|
||||
create(req:TaskServiceCreateReq){
|
||||
const userId = req.userId;
|
||||
return new TaskServiceGetter(userId,this.ctx)
|
||||
return new TaskServiceGetter(userId,this.appCtx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,6 +123,22 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
const result = await super.page(pageReq);
|
||||
await this.fillLastVars(result.records);
|
||||
|
||||
for (const item of result.records) {
|
||||
if (!item.content){
|
||||
continue
|
||||
}
|
||||
const pipeline = JSON.parse(item.content);
|
||||
let stepCount = 0
|
||||
RunnableCollection.each(pipeline.stages, (runnable: any) => {
|
||||
stepCount++
|
||||
})
|
||||
// @ts-ignore
|
||||
item.stepCount = stepCount
|
||||
// @ts-ignore
|
||||
item.triggerCount = pipeline.triggers.length
|
||||
delete item.content
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -637,7 +653,7 @@ export class PipelineService extends BaseService<PipelineEntity> {
|
||||
//修改pipeline状态
|
||||
const pipelineEntity = new PipelineEntity();
|
||||
pipelineEntity.id = parseInt(history.pipeline.id);
|
||||
pipelineEntity.status = history.pipeline.status.status + '';
|
||||
pipelineEntity.status = history.pipeline.status.result + '';
|
||||
pipelineEntity.lastHistoryTime = history.pipeline.status.startTime;
|
||||
await this.update(pipelineEntity);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user