Skip to content

Commit d6d76fb

Browse files
authored
wip: optimisation (#6473)
1 parent 22ea761 commit d6d76fb

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

internal/sql/repository/pipelineConfig/CiWorkflowRepository.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ func (impl *CiWorkflowRepositoryImpl) UpdateArtifactUploaded(id int, isUploaded
284284
func (impl *CiWorkflowRepositoryImpl) FindLastTriggeredWorkflowByCiIds(pipelineId []int) (ciWorkflow []*CiWorkflow, err error) {
285285
err = impl.dbConnection.Model(&ciWorkflow).
286286
Column("ci_workflow.*", "CiPipeline").
287-
Where("ci_workflow.ci_pipeline_id in (?) ", pg.In(pipelineId)).
288-
Order("ci_workflow.started_on Desc").
287+
Where("ci_workflow.id IN (select MAX(id) from ci_workflow where ci_pipeline_id IN (?) GROUP BY ci_pipeline_id)", pg.In(pipelineId)).
289288
Select()
290289
return ciWorkflow, err
291290
}

pkg/pipeline/CiHandler.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -1818,20 +1818,14 @@ func (impl *CiHandlerImpl) FetchCiStatusForTriggerViewForEnvironment(request res
18181818
if len(ciPipelineIds) == 0 {
18191819
return ciWorkflowStatuses, nil
18201820
}
1821-
ciWorkflows, err := impl.ciWorkflowRepository.FindLastTriggeredWorkflowByCiIds(ciPipelineIds)
1821+
latestCiWorkflows, err := impl.ciWorkflowRepository.FindLastTriggeredWorkflowByCiIds(ciPipelineIds)
18221822
if err != nil && !util.IsErrNoRows(err) {
18231823
impl.Logger.Errorw("err", "ciPipelineIds", ciPipelineIds, "err", err)
18241824
return ciWorkflowStatuses, err
18251825
}
18261826

18271827
notTriggeredWorkflows := make(map[int]bool)
1828-
latestCiWorkflows := make(map[int]*pipelineConfig.CiWorkflow)
1829-
for _, ciWorkflow := range ciWorkflows {
1830-
//adding only latest status in the list
1831-
if _, ok := latestCiWorkflows[ciWorkflow.CiPipelineId]; !ok {
1832-
latestCiWorkflows[ciWorkflow.CiPipelineId] = ciWorkflow
1833-
}
1834-
}
1828+
18351829
for _, ciWorkflow := range latestCiWorkflows {
18361830
ciWorkflowStatus := &pipelineConfig.CiWorkflowStatus{}
18371831
ciWorkflowStatus.CiPipelineId = ciWorkflow.CiPipelineId

0 commit comments

Comments
 (0)