Skip to content

Commit 635d86a

Browse files
authored
fix: update app details handling and sync logic in app_sync_task (#11830)
- 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.
1 parent 607eae3 commit 635d86a

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

agent/app/service/app_sync_task.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ func (c *appSyncContext) classifyAndPersistAppsWithStats(addCount, updateCount,
363363
for _, app := range addAppArray {
364364
if existing, ok := existingMap[app.Key]; ok {
365365
app.ID = existing.ID
366-
app.Details = existing.Details
366+
if len(app.Details) == 0 {
367+
app.Details = existing.Details
368+
}
367369
updateAppArray = append(updateAppArray, app)
368370
} else {
369371
filteredAdd = append(filteredAdd, app)
@@ -477,27 +479,31 @@ func (c *appSyncContext) classifyAndPersistAppsWithStats(addCount, updateCount,
477479
}
478480
}
479481

480-
syncedAppIds := make([]uint, 0, len(addAppArray)+len(updateAppArray)+len(deleteIds))
481-
for _, app := range addAppArray {
482-
if app.ID > 0 {
483-
syncedAppIds = append(syncedAppIds, app.ID)
482+
if len(c.appTags) > 0 {
483+
syncedAppIds := make([]uint, 0, len(addAppArray)+len(updateAppArray)+len(deleteIds))
484+
for _, app := range addAppArray {
485+
if app.ID > 0 && app.Resource == constant.AppResourceRemote {
486+
syncedAppIds = append(syncedAppIds, app.ID)
487+
}
484488
}
485-
}
486-
for _, app := range updateAppArray {
487-
syncedAppIds = append(syncedAppIds, app.ID)
488-
}
489-
syncedAppIds = append(syncedAppIds, deleteIds...)
490-
491-
if len(syncedAppIds) > 0 {
492-
if err = appTagRepo.DeleteByAppIds(ctx, syncedAppIds); err != nil {
493-
return
489+
for _, app := range updateAppArray {
490+
if app.Resource == constant.AppResourceRemote {
491+
syncedAppIds = append(syncedAppIds, app.ID)
492+
}
493+
}
494+
syncedAppIds = append(syncedAppIds, deleteIds...)
495+
if len(syncedAppIds) > 0 {
496+
if err = appTagRepo.DeleteByAppIds(ctx, syncedAppIds); err != nil {
497+
return
498+
}
494499
}
495-
}
496-
497-
if len(c.appTags) > 0 {
498500
if err = appTagRepo.BatchCreate(ctx, c.appTags); err != nil {
499501
return
500502
}
503+
} else if len(deleteIds) > 0 {
504+
if err = appTagRepo.DeleteByAppIds(ctx, deleteIds); err != nil {
505+
return
506+
}
501507
}
502508

503509
if err = tx.Commit().Error; err != nil {

0 commit comments

Comments
 (0)