Skip to content

Commit c411b64

Browse files
authored
Merge pull request #13 from devtron-labs/sqlscript-and-applisting-fix
hotfixes
2 parents 32b6a36 + cae7b7f commit c411b64

File tree

2 files changed

+55
-51
lines changed

2 files changed

+55
-51
lines changed

internal/sql/repository/pipelineConfig/CiPipelineRepository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type CiPipeline struct {
3838
Deleted bool `sql:"deleted,notnull"`
3939
IsManual bool `sql:"manual,notnull"`
4040
IsExternal bool `sql:"external,notnull"`
41-
ParentCiPipeline int `sql:"parent_ci_pipeline,notnull"`
41+
ParentCiPipeline int `sql:"parent_ci_pipeline"`
4242
ScanEnabled bool `sql:"scan_enabled,notnull"`
4343
models.AuditLog
4444
CiPipelineMaterials []*CiPipelineMaterial

pkg/app/AppListingService.go

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ package app
1919

2020
import (
2121
"context"
22+
"encoding/json"
23+
"fmt"
24+
"github.com/argoproj/argo-cd/pkg/apiclient/application"
25+
"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
2226
"github.com/devtron-labs/devtron/api/bean"
2327
application2 "github.com/devtron-labs/devtron/client/argocdServer/application"
2428
"github.com/devtron-labs/devtron/internal/constants"
@@ -29,10 +33,6 @@ import (
2933
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
3034
"github.com/devtron-labs/devtron/internal/util"
3135
"github.com/devtron-labs/devtron/pkg/prometheus"
32-
"encoding/json"
33-
"fmt"
34-
"github.com/argoproj/argo-cd/pkg/apiclient/application"
35-
"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
3636
"github.com/go-pg/pg"
3737
"github.com/pkg/errors"
3838
"github.com/prometheus/client_golang/api/prometheus/v1"
@@ -228,61 +228,65 @@ func (impl AppListingServiceImpl) fetchACDAppStatus(fetchAppListingRequest Fetch
228228
for _, p := range pipelinesAll {
229229
pipelineIds = append(pipelineIds, p.Id)
230230
}
231-
if pipelineIds == nil || len(pipelineIds) == 0 {
231+
232+
/*if pipelineIds == nil || len(pipelineIds) == 0 {
232233
return appEnvMapping, err
233-
}
234-
// from all the active pipeline, get all the cd workflow
235-
cdWorkflowAll, err := impl.cdWorkflowRepository.FindLatestCdWorkflowByPipelineIdV2(pipelineIds) //TODO - OPTIMIZE 2
236-
if err != nil && !util.IsErrNoRows(err) {
237-
impl.Logger.Error(err)
238-
return nil, err
239-
}
234+
}*/
235+
236+
if len(pipelineIds) > 0 {
237+
// from all the active pipeline, get all the cd workflow
238+
cdWorkflowAll, err := impl.cdWorkflowRepository.FindLatestCdWorkflowByPipelineIdV2(pipelineIds) //TODO - OPTIMIZE 2
239+
if err != nil && !util.IsErrNoRows(err) {
240+
impl.Logger.Error(err)
241+
return nil, err
242+
}
240243

241-
//here to build a map of pipelines list for each (appId and envId)
242-
for _, p := range pipelinesAll {
243-
key := fmt.Sprintf("%d-%d", p.AppId, p.EnvironmentId)
244-
if _, ok := appEnvPipelinesMap[key]; !ok {
245-
var appEnvPipelines []*pipelineConfig.Pipeline
246-
appEnvPipelines = append(appEnvPipelines, p)
247-
appEnvPipelinesMap[key] = appEnvPipelines
248-
} else {
249-
appEnvPipelinesMap[key] = append(appEnvPipelinesMap[key], p)
244+
//here to build a map of pipelines list for each (appId and envId)
245+
for _, p := range pipelinesAll {
246+
key := fmt.Sprintf("%d-%d", p.AppId, p.EnvironmentId)
247+
if _, ok := appEnvPipelinesMap[key]; !ok {
248+
var appEnvPipelines []*pipelineConfig.Pipeline
249+
appEnvPipelines = append(appEnvPipelines, p)
250+
appEnvPipelinesMap[key] = appEnvPipelines
251+
} else {
252+
appEnvPipelinesMap[key] = append(appEnvPipelinesMap[key], p)
253+
}
250254
}
251-
}
252255

253-
// find and build a map of latest cd workflow for each (appId and envId), single latest CDWF for any of the cd pipelines.
254-
var wfIds []int
255-
for key, v := range appEnvPipelinesMap {
256-
if _, ok := appEnvCdWorkflowMap[key]; !ok {
257-
for _, itemW := range cdWorkflowAll {
258-
for _, itemP := range v {
259-
if itemW.PipelineId == itemP.Id {
260-
// GOT LATEST CD WF, AND PUT INTO MAP
261-
appEnvCdWorkflowMap[key] = itemW
262-
wfIds = append(wfIds, itemW.Id)
256+
// find and build a map of latest cd workflow for each (appId and envId), single latest CDWF for any of the cd pipelines.
257+
var wfIds []int
258+
for key, v := range appEnvPipelinesMap {
259+
if _, ok := appEnvCdWorkflowMap[key]; !ok {
260+
for _, itemW := range cdWorkflowAll {
261+
for _, itemP := range v {
262+
if itemW.PipelineId == itemP.Id {
263+
// GOT LATEST CD WF, AND PUT INTO MAP
264+
appEnvCdWorkflowMap[key] = itemW
265+
wfIds = append(wfIds, itemW.Id)
266+
}
263267
}
264268
}
265-
}
266-
//if no cd wf found for appid-envid, add it into map with nil
267-
if _, ok := appEnvCdWorkflowMap[key]; !ok {
268-
appEnvCdWorkflowMap[key] = nil
269+
//if no cd wf found for appid-envid, add it into map with nil
270+
if _, ok := appEnvCdWorkflowMap[key]; !ok {
271+
appEnvCdWorkflowMap[key] = nil
272+
}
269273
}
270274
}
271-
}
272275

273-
//fetch all the cd workflow runner from cdWF ids,
274-
cdWorkflowRunnersAll, err := impl.cdWorkflowRepository.FindWorkflowRunnerByCdWorkflowId(wfIds) //TODO - OPTIMIZE 3
275-
if err != nil {
276-
impl.Logger.Errorw("error in getting wf", "err", err)
277-
}
278-
//build a map with key cdWF containing cdWFRunner List, which are later put in map for further requirement
279-
for _, item := range cdWorkflowRunnersAll {
280-
if _, ok := appEnvCdWorkflowRunnerMap[item.CdWorkflowId]; !ok {
281-
var cdWorkflowRunners []*pipelineConfig.CdWorkflowRunner
282-
cdWorkflowRunners = append(cdWorkflowRunners, item)
283-
appEnvCdWorkflowRunnerMap[item.CdWorkflowId] = cdWorkflowRunners
284-
} else {
285-
appEnvCdWorkflowRunnerMap[item.CdWorkflowId] = append(appEnvCdWorkflowRunnerMap[item.CdWorkflowId], item)
276+
//fetch all the cd workflow runner from cdWF ids,
277+
cdWorkflowRunnersAll, err := impl.cdWorkflowRepository.FindWorkflowRunnerByCdWorkflowId(wfIds) //TODO - OPTIMIZE 3
278+
if err != nil {
279+
impl.Logger.Errorw("error in getting wf", "err", err)
280+
}
281+
//build a map with key cdWF containing cdWFRunner List, which are later put in map for further requirement
282+
for _, item := range cdWorkflowRunnersAll {
283+
if _, ok := appEnvCdWorkflowRunnerMap[item.CdWorkflowId]; !ok {
284+
var cdWorkflowRunners []*pipelineConfig.CdWorkflowRunner
285+
cdWorkflowRunners = append(cdWorkflowRunners, item)
286+
appEnvCdWorkflowRunnerMap[item.CdWorkflowId] = cdWorkflowRunners
287+
} else {
288+
appEnvCdWorkflowRunnerMap[item.CdWorkflowId] = append(appEnvCdWorkflowRunnerMap[item.CdWorkflowId], item)
289+
}
286290
}
287291
}
288292

0 commit comments

Comments
 (0)