From 537ff49c0ba1cbadd638ecb63d0eb3d1911f481c Mon Sep 17 00:00:00 2001 From: KOMATA <20227709+HynoR@users.noreply.github.com> Date: Mon, 9 Feb 2026 15:33:05 +0800 Subject: [PATCH] f (#11834) --- agent/app/service/app_sync_task.go | 38 ++++++++++-------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/agent/app/service/app_sync_task.go b/agent/app/service/app_sync_task.go index a228634ff..e9cd16927 100644 --- a/agent/app/service/app_sync_task.go +++ b/agent/app/service/app_sync_task.go @@ -427,10 +427,13 @@ func (c *appSyncContext) classifyAndPersistAppsWithStats(addCount, updateCount, for _, tag := range app.TagsKey { tagId, ok := tagMap[tag] if ok { - c.appTags = append(c.appTags, &model.AppTag{ - AppId: app.ID, - TagId: tagId, - }) + exist, _ := appTagRepo.GetFirst(ctx, appTagRepo.WithByTagID(tagId), appTagRepo.WithByAppID(app.ID)) + if exist == nil { + c.appTags = append(c.appTags, &model.AppTag{ + AppId: app.ID, + TagId: tagId, + }) + } } } @@ -479,29 +482,14 @@ func (c *appSyncContext) classifyAndPersistAppsWithStats(addCount, updateCount, } } - 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 { - 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 err = appTagRepo.BatchCreate(ctx, c.appTags); err != nil { + if len(c.oldAppIds) > 0 { + if err = appTagRepo.DeleteByAppIds(ctx, deleteIds); err != nil { return } - } else if len(deleteIds) > 0 { - if err = appTagRepo.DeleteByAppIds(ctx, deleteIds); err != nil { + } + + if len(c.appTags) > 0 { + if err = appTagRepo.BatchCreate(ctx, c.appTags); err != nil { return } }