From 6eb0076cf4fe3d12717781d3b71e981d59d2ee7e Mon Sep 17 00:00:00 2001 From: zhengkunwang223 <1paneldev@sina.com> Date: Wed, 5 Nov 2025 11:10:58 +0800 Subject: [PATCH] feat: Optimize the check for deleting associated databases when removing an application. --- agent/app/dto/response/app.go | 1 + agent/app/service/app_utils.go | 69 +++++++++++-------- frontend/src/api/interface/app.ts | 1 + .../app-store/installed/delete/index.vue | 4 +- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/agent/app/dto/response/app.go b/agent/app/dto/response/app.go index 50d5cfe59311..c97f62bf742d 100644 --- a/agent/app/dto/response/app.go +++ b/agent/app/dto/response/app.go @@ -129,6 +129,7 @@ type AppInstallDTO struct { App AppDetail `json:"app"` Container string `json:"container"` IsEdit bool `json:"isEdit"` + LinkDB bool `json:"linkDB"` } type AppInstallInfo struct { diff --git a/agent/app/service/app_utils.go b/agent/app/service/app_utils.go index 09c1e5ca7b47..6417af7e7e84 100644 --- a/agent/app/service/app_utils.go +++ b/agent/app/service/app_utils.go @@ -1567,43 +1567,37 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) Favorite: installed.Favorite, Container: installed.ContainerName, } - if updated { - detail, _ := appDetailRepo.GetFirst(repo.WithByID(installed.AppDetailId)) - installDTO.DockerCompose = installed.DockerCompose - rawCompose, _ := getUpgradeCompose(installed, detail) - if rawCompose != installed.DockerCompose { - installDTO.IsEdit = true - } + if !updated { + installDTO.LinkDB = hasLinkDB(installed.ID) + res = append(res, installDTO) + continue } - app, err := appRepo.GetFirst(repo.WithByID(installed.AppId)) - if err != nil { - return nil, err + if installed.Version == "latest" { + continue } - details, err := appDetailRepo.GetBy(appDetailRepo.WithAppId(app.ID)) + installDTO.DockerCompose = installed.DockerCompose + installDTO.IsEdit = isEditCompose(installed) + details, err := appDetailRepo.GetBy(appDetailRepo.WithAppId(installed.App.ID)) if err != nil { return nil, err } var versions []string - for _, detail := range details { - ignores, _ := appIgnoreUpgradeRepo.List(runtimeRepo.WithDetailId(detail.ID), appIgnoreUpgradeRepo.WithScope("version")) - if len(ignores) > 0 || installed.Version == "latest" { + for _, appDetail := range details { + ignores, _ := appIgnoreUpgradeRepo.List(runtimeRepo.WithDetailId(appDetail.ID), appIgnoreUpgradeRepo.WithScope("version")) + if len(ignores) > 0 { continue } - if common.IsCrossVersion(installed.Version, detail.Version) && !app.CrossVersionUpdate { + if common.IsCrossVersion(installed.Version, appDetail.Version) && !installed.App.CrossVersionUpdate { continue } - versions = append(versions, detail.Version) + versions = append(versions, appDetail.Version) } - versions = common.GetSortedVersions(versions) if len(versions) == 0 { - if !updated { - installDTO.CanUpdate = false - res = append(res, installDTO) - } continue } + versions = common.GetSortedVersions(versions) lastVersion := versions[0] - if app.Key == constant.AppMysql || app.Key == constant.AppMysqlCluster { + if installed.App.Key == constant.AppMysql || installed.App.Key == constant.AppMysqlCluster { for _, version := range versions { majorVersion := getMajorVersion(installed.Version) if !strings.HasPrefix(version, majorVersion) { @@ -1615,15 +1609,11 @@ func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) } } if common.IsCrossVersion(installed.Version, lastVersion) { - installDTO.CanUpdate = app.CrossVersionUpdate + installDTO.CanUpdate = installed.App.CrossVersionUpdate } else { installDTO.CanUpdate = common.CompareVersion(lastVersion, installed.Version) } - if updated { - if installDTO.CanUpdate { - res = append(res, installDTO) - } - } else { + if installDTO.CanUpdate { res = append(res, installDTO) } } @@ -2142,3 +2132,26 @@ func needsUpdate(localTag *model.Tag, remoteTag dto.Tag, translations string) bo localTag.Sort != remoteTag.Sort || localTag.Translations != translations } + +func hasLinkDB(installID uint) bool { + resources, _ := appInstallResourceRepo.GetBy(appInstallResourceRepo.WithAppInstallId(installID)) + if len(resources) > 0 { + for _, resource := range resources { + if resource.Key == constant.AppPostgres || resource.Key == constant.AppMysql || + resource.Key == constant.AppMariaDB || resource.Key == constant.AppMysqlCluster || + resource.Key == constant.AppPostgresql || resource.Key == constant.AppPostgresqlCluster { + return true + } + } + } + return false +} + +func isEditCompose(installed model.AppInstall) bool { + detail, _ := appDetailRepo.GetFirst(repo.WithByID(installed.AppDetailId)) + rawCompose, _ := getUpgradeCompose(installed, detail) + if rawCompose != installed.DockerCompose { + return true + } + return false +} diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index 208200de6bb8..d6f286cf71f9 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -187,6 +187,7 @@ export namespace App { isEdit: boolean; dockerCompose: string; app: App.AppDetail; + linkDB: boolean; } export interface AppInstalledInfo { diff --git a/frontend/src/views/app-store/installed/delete/index.vue b/frontend/src/views/app-store/installed/delete/index.vue index f3d10db019b4..05f301007d68 100644 --- a/frontend/src/views/app-store/installed/delete/index.vue +++ b/frontend/src/views/app-store/installed/delete/index.vue @@ -25,7 +25,7 @@ {{ $t('app.deleteImageHelper') }} - + {{ $t('app.deleteDBHelper') }} @@ -76,6 +76,7 @@ const deleteInfo = ref(''); const appInstallName = ref(''); const appType = ref(''); const taskLogRef = ref(); +const linkDB = ref(false); const deleteForm = ref(); const em = defineEmits(['close']); @@ -107,6 +108,7 @@ const acceptParams = async (app: App.AppInstallDto) => { appType.value = app.appType; deleteHelper.value = i18n.global.t('website.deleteConfirmHelper', [app.name]); appInstallName.value = app.name; + linkDB.value = app.linkDB; open.value = true; };