diff --git a/push/topology.go b/push/topology.go index a69bdba3..59accaea 100644 --- a/push/topology.go +++ b/push/topology.go @@ -4,7 +4,7 @@ import ( "encoding/json" "io" - "github.com/flanksource/commons/properties" + "github.com/flanksource/duty" dutyAPI "github.com/flanksource/duty/api" "github.com/flanksource/duty/context" dutydb "github.com/flanksource/duty/db" @@ -13,7 +13,6 @@ import ( "github.com/flanksource/incident-commander/db" "github.com/google/uuid" "github.com/labstack/echo/v4" - "github.com/samber/lo" ) func PushTopology(c echo.Context) error { @@ -69,20 +68,14 @@ func PushTopology(c echo.Context) error { return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error saving components: %v", dutydb.ErrorDetails(err))) } - var idsToDelete []string - if err := ctx.DB().Model(&models.Component{}).Select("id").Where("topology_id = ?", data.TopologyID).Where("deleted_at IS NULL").Where("id NOT IN ?", returnedIDs).Find(&idsToDelete).Error; err != nil { + // Soft delete component ids which were not created + if err := ctx.DB().Model(&models.Component{}). + Where("topology_id = ?", data.TopologyID). + Where("deleted_at IS NULL"). + Where("id NOT IN ?", returnedIDs). + UpdateColumn("deleted_at", duty.Now()).Error; err != nil { return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error querying old components: %v", dutydb.ErrorDetails(err))) } - if len(idsToDelete) > 0 { - chunkSize := properties.Int(5000, "push.topology.delete_chunk_size") - chunks := lo.Chunk(idsToDelete, chunkSize) - for _, chunk := range chunks { - if err := models.DeleteComponentsWithIDs(ctx.DB(), chunk); err != nil { - return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "error deleting old components: %v", dutydb.ErrorDetails(err))) - } - } - } - return dutyAPI.WriteSuccess(c, data) }