Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sql query optimisation for application group app status listing #5672

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions internal/sql/repository/pipelineConfig/CdWorfkflowRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type CdWorkflowRepository interface {
FetchAllCdStagesLatestEntity(pipelineIds []int) ([]*CdWorkflowStatus, error)
FetchAllCdStagesLatestEntityStatus(wfrIds []int) ([]*CdWorkflowRunner, error)
ExistsByStatus(status string) (bool, error)

FetchEnvAllCdStagesLatestEntityStatus(wfrIds []int, envID int) ([]*CdWorkflowRunner, error)
FetchArtifactsByCdPipelineId(pipelineId int, runnerType apiBean.WorkflowType, offset, limit int, searchString string) ([]CdWorkflowRunner, error)
GetLatestTriggersOfHelmPipelinesStuckInNonTerminalStatuses(getPipelineDeployedWithinHours int) ([]*CdWorkflowRunner, error)
FindLatestRunnerByPipelineIdsAndRunnerType(ctx context.Context, pipelineIds []int, runnerType apiBean.WorkflowType) ([]CdWorkflowRunner, error)
Expand Down Expand Up @@ -685,8 +685,23 @@ func (impl *CdWorkflowRepositoryImpl) FetchAllCdStagesLatestEntity(pipelineIds [

func (impl *CdWorkflowRepositoryImpl) FetchAllCdStagesLatestEntityStatus(wfrIds []int) ([]*CdWorkflowRunner, error) {
var wfrList []*CdWorkflowRunner
err := impl.dbConnection.Model(&wfrList).Column("cd_workflow_runner.*").
Where("cd_workflow_runner.id in (?)", pg.In(wfrIds)).Select()
err := impl.dbConnection.Model(&wfrList).
Column("cd_workflow_runner.id", "cd_workflow_runner.status").
Where("cd_workflow_runner.id in (?)", pg.In(wfrIds)).
Select()
return wfrList, err
}

func (impl *CdWorkflowRepositoryImpl) FetchEnvAllCdStagesLatestEntityStatus(wfrIds []int, envID int) ([]*CdWorkflowRunner, error) {
var wfrList []*CdWorkflowRunner
query := `
select wfr.id, wfr.status
from cd_workflow_runner wfr
inner join cd_workflow wf on wf.id = wfr.cd_workflow_id
inner join pipeline p on p.id = wf.pipeline_id
where p.environment_id = ? and wfr.id in (?)
`
_, err := impl.dbConnection.Query(&wfrList, query, envID, pg.In(wfrIds))
return wfrList, err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/pipeline/CdHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ func (impl *CdHandlerImpl) FetchAppWorkflowStatusForTriggerViewForEnvironment(re

statusMap := make(map[int]string)
if len(wfrIds) > 0 {
cdWorkflowRunners, err := impl.cdWorkflowRepository.FetchAllCdStagesLatestEntityStatus(wfrIds)
cdWorkflowRunners, err := impl.cdWorkflowRepository.FetchEnvAllCdStagesLatestEntityStatus(wfrIds, request.ParentResourceId)
if err != nil && !util.IsErrNoRows(err) {
return cdWorkflowStatus, err
}
Expand Down Expand Up @@ -1130,7 +1130,7 @@ func (impl *CdHandlerImpl) FetchAppDeploymentStatusForEnvironments(request resou
}
if len(wfrIds) > 0 {
_, span = otel.Tracer("orchestrator").Start(request.Ctx, "pipelineBuilder.FetchAllCdStagesLatestEntityStatus")
wfrList, err := impl.cdWorkflowRepository.FetchAllCdStagesLatestEntityStatus(wfrIds)
wfrList, err := impl.cdWorkflowRepository.FetchEnvAllCdStagesLatestEntityStatus(wfrIds, request.ParentResourceId)
span.End()
if err != nil && !util.IsErrNoRows(err) {
return deploymentStatuses, err
Expand Down
Loading