diff --git a/agent/app/repo/runtime.go b/agent/app/repo/runtime.go index cc23def474d5..c32dd30e2c4f 100644 --- a/agent/app/repo/runtime.go +++ b/agent/app/repo/runtime.go @@ -17,6 +17,7 @@ type IRuntimeRepo interface { WithNotId(id uint) DBOption WithStatus(status string) DBOption WithDetailId(id uint) DBOption + WithDetailIdsIn(ids []uint) DBOption WithPort(port int) DBOption WithNormalStatus(status string) DBOption Page(page, size int, opts ...DBOption) (int64, []model.Runtime, error) @@ -55,6 +56,12 @@ func (r *RuntimeRepo) WithDetailId(id uint) DBOption { } } +func (r *RuntimeRepo) WithDetailIdsIn(ids []uint) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("app_detail_id in(?) ", ids) + } +} + func (r *RuntimeRepo) WithNotId(id uint) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("id != ?", id) diff --git a/agent/app/service/app.go b/agent/app/service/app.go index 735bf56c5e4a..f66058e61204 100644 --- a/agent/app/service/app.go +++ b/agent/app/service/app.go @@ -132,8 +132,21 @@ func (a AppService) PageApp(ctx *gin.Context, req request.AppSearch) (interface{ continue } appDTO.Tags = tags - installs, _ := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithAppId(ap.ID)) - appDTO.Installed = len(installs) > 0 + if ap.Type == constant.RuntimePHP || ap.Type == constant.RuntimeGo || ap.Type == constant.RuntimeNode || ap.Type == constant.RuntimePython || ap.Type == constant.RuntimeJava || ap.Type == constant.RuntimeDotNet { + details, _ := appDetailRepo.GetBy(appDetailRepo.WithAppId(ap.ID)) + var ids []uint + if len(details) == 0 { + continue + } + for _, d := range details { + ids = append(ids, d.ID) + } + runtimes, _ := runtimeRepo.List(runtimeRepo.WithDetailIdsIn(ids)) + appDTO.Installed = len(runtimes) > 0 + } else { + installs, _ := appInstallRepo.ListBy(context.Background(), appInstallRepo.WithAppId(ap.ID)) + appDTO.Installed = len(installs) > 0 + } } res.Items = appDTOs res.Total = total