Skip to content

Commit de43a47

Browse files
committed
refactor
1 parent 2517961 commit de43a47

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

internal/sql/repository/AppListingRepository.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type AppListingRepository interface {
5151
DeploymentDetailByArtifactId(ciArtifactId int, envId int) (AppView.DeploymentDetailContainer, error)
5252
FindAppCount(isProd bool) (int, error)
5353
FetchAppsByEnvironmentV2(appListingFilter helper.AppListingFilter) ([]*AppView.AppEnvironmentContainer, int, error)
54-
FetchAppsEnvContainers(envId, limit, offset int) ([]*AppView.AppEnvironmentContainer, error)
54+
FetchAppsEnvContainers(envId, limit, offset int, appIds []int) ([]*AppView.AppEnvironmentContainer, error)
5555
FetchLastDeployedImage(appId, envId int) (*LastDeployed, error)
5656
}
5757

@@ -137,25 +137,35 @@ func (impl *AppListingRepositoryImpl) FetchOverviewCiPipelines(jobId int) ([]*Ap
137137
return jobContainers, nil
138138
}
139139

140-
func (impl *AppListingRepositoryImpl) FetchAppsEnvContainers(envId, limit, offset int) ([]*AppView.AppEnvironmentContainer, error) {
140+
func (impl *AppListingRepositoryImpl) FetchAppsEnvContainers(envId int, limit, offset int, appIds []int) ([]*AppView.AppEnvironmentContainer, error) {
141141
query := ` SELECT a.id as app_id,a.app_name,aps.status as app_status, ld.last_deployed_time, p.id as pipeline_id
142142
FROM app a
143143
INNER JOIN pipeline p ON p.app_id = a.id and p.deleted = false and p.environment_id = ?
144144
LEFT JOIN app_status aps ON aps.app_id = a.id and aps.env_id = ?
145145
LEFT JOIN
146146
(SELECT pco.pipeline_id,MAX(pco.created_on) as last_deployed_time from pipeline_config_override pco
147147
GROUP BY pco.pipeline_id) ld ON ld.pipeline_id = p.id
148-
WHERE a.active = true
149-
ORDER BY a.app_name `
148+
WHERE a.active = true`
149+
150150
queryParams := []interface{}{envId, envId}
151+
152+
// Add app IDs filter if provided
153+
if len(appIds) > 0 {
154+
query += " AND a.id IN (?)"
155+
queryParams = append(queryParams, pg.In(appIds))
156+
}
157+
158+
query += " ORDER BY a.app_name"
159+
151160
if limit > 0 {
152-
query += fmt.Sprintf("LIMIT ? ")
161+
query += " LIMIT ?"
153162
queryParams = append(queryParams, limit)
154163
}
155164
if offset > 0 {
156-
query += fmt.Sprintf("OFFSET ? ")
165+
query += " OFFSET ?"
157166
queryParams = append(queryParams, offset)
158167
}
168+
159169
var envContainers []*AppView.AppEnvironmentContainer
160170
_, err := impl.dbConnection.Query(&envContainers, query, queryParams...)
161171
return envContainers, err

pkg/app/AppListingService.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ func (impl AppListingServiceImpl) FetchOverviewAppsByEnvironment(envId, limit, o
233233
resp.CreatedBy = fmt.Sprintf("%s (inactive)", createdBy.EmailId)
234234
}
235235
}
236-
envContainers, err := impl.FetchAppsEnvContainers(envId, limit, offset)
236+
var appIds []int
237+
envContainers, err := impl.FetchAppsEnvContainers(envId, limit, offset, appIds)
237238
if err != nil {
238239
impl.Logger.Errorw("failed to fetch env containers", "err", err, "envId", envId)
239240
return resp, err
@@ -287,8 +288,8 @@ func getUniqueArtifacts(artifactIds []int) (uniqueArtifactIds []int) {
287288
return uniqueArtifactIds
288289
}
289290

290-
func (impl AppListingServiceImpl) FetchAppsEnvContainers(envId, limit, offset int) ([]*AppView.AppEnvironmentContainer, error) {
291-
envContainers, err := impl.appListingRepository.FetchAppsEnvContainers(envId, limit, offset)
291+
func (impl AppListingServiceImpl) FetchAppsEnvContainers(envId, limit, offset int, appIds []int) ([]*AppView.AppEnvironmentContainer, error) {
292+
envContainers, err := impl.appListingRepository.FetchAppsEnvContainers(envId, limit, offset, appIds)
292293
if err != nil {
293294
impl.Logger.Errorw("failed to fetch environment containers", "err", err, "envId", envId)
294295
return nil, err

wire_gen.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)