From 7b998bf3d5cc27d0043685ae0c7113011f8de7dd Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Mon, 9 Feb 2026 12:55:05 +0800 Subject: [PATCH] fix: update app details handling and sync logic in app_sync_task - Modified the logic to retain app details computed from remote sources, only falling back to existing details when necessary. - Enhanced the synchronization process to ensure only remote resources are included in the synced app IDs for both addition and update scenarios. --- agent/app/service/app_sync_task.go | 40 +++++++++++++++++------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/agent/app/service/app_sync_task.go b/agent/app/service/app_sync_task.go index b165c11bc94d..a228634ff1f3 100644 --- a/agent/app/service/app_sync_task.go +++ b/agent/app/service/app_sync_task.go @@ -363,7 +363,9 @@ func (c *appSyncContext) classifyAndPersistAppsWithStats(addCount, updateCount, for _, app := range addAppArray { if existing, ok := existingMap[app.Key]; ok { app.ID = existing.ID - app.Details = existing.Details + if len(app.Details) == 0 { + app.Details = existing.Details + } updateAppArray = append(updateAppArray, app) } else { filteredAdd = append(filteredAdd, app) @@ -477,27 +479,31 @@ func (c *appSyncContext) classifyAndPersistAppsWithStats(addCount, updateCount, } } - syncedAppIds := make([]uint, 0, len(addAppArray)+len(updateAppArray)+len(deleteIds)) - for _, app := range addAppArray { - if app.ID > 0 { - syncedAppIds = append(syncedAppIds, app.ID) + if len(c.appTags) > 0 { + syncedAppIds := make([]uint, 0, len(addAppArray)+len(updateAppArray)+len(deleteIds)) + for _, app := range addAppArray { + if app.ID > 0 && app.Resource == constant.AppResourceRemote { + syncedAppIds = append(syncedAppIds, app.ID) + } } - } - for _, app := range updateAppArray { - syncedAppIds = append(syncedAppIds, app.ID) - } - syncedAppIds = append(syncedAppIds, deleteIds...) - - if len(syncedAppIds) > 0 { - if err = appTagRepo.DeleteByAppIds(ctx, syncedAppIds); err != nil { - return + for _, app := range updateAppArray { + if app.Resource == constant.AppResourceRemote { + syncedAppIds = append(syncedAppIds, app.ID) + } + } + syncedAppIds = append(syncedAppIds, deleteIds...) + if len(syncedAppIds) > 0 { + if err = appTagRepo.DeleteByAppIds(ctx, syncedAppIds); err != nil { + return + } } - } - - if len(c.appTags) > 0 { if err = appTagRepo.BatchCreate(ctx, c.appTags); err != nil { return } + } else if len(deleteIds) > 0 { + if err = appTagRepo.DeleteByAppIds(ctx, deleteIds); err != nil { + return + } } if err = tx.Commit().Error; err != nil {