Skip to content

Commit 0dacf1f

Browse files
committed
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.
1 parent 607eae3 commit 0dacf1f

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

agent/app/service/app_sync_task.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,10 @@ 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+
// Keep details computed from remote in meta sync; only fallback when missing.
367+
if len(app.Details) == 0 {
368+
app.Details = existing.Details
369+
}
367370
updateAppArray = append(updateAppArray, app)
368371
} else {
369372
filteredAdd = append(filteredAdd, app)
@@ -477,27 +480,31 @@ func (c *appSyncContext) classifyAndPersistAppsWithStats(addCount, updateCount,
477480
}
478481
}
479482

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)
483+
if len(c.appTags) > 0 {
484+
syncedAppIds := make([]uint, 0, len(addAppArray)+len(updateAppArray)+len(deleteIds))
485+
for _, app := range addAppArray {
486+
if app.ID > 0 && app.Resource == constant.AppResourceRemote {
487+
syncedAppIds = append(syncedAppIds, app.ID)
488+
}
484489
}
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
490+
for _, app := range updateAppArray {
491+
if app.Resource == constant.AppResourceRemote {
492+
syncedAppIds = append(syncedAppIds, app.ID)
493+
}
494+
}
495+
syncedAppIds = append(syncedAppIds, deleteIds...)
496+
if len(syncedAppIds) > 0 {
497+
if err = appTagRepo.DeleteByAppIds(ctx, syncedAppIds); err != nil {
498+
return
499+
}
494500
}
495-
}
496-
497-
if len(c.appTags) > 0 {
498501
if err = appTagRepo.BatchCreate(ctx, c.appTags); err != nil {
499502
return
500503
}
504+
} else if len(deleteIds) > 0 {
505+
if err = appTagRepo.DeleteByAppIds(ctx, deleteIds); err != nil {
506+
return
507+
}
501508
}
502509

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

0 commit comments

Comments
 (0)