diff --git a/models/checks.go b/models/checks.go index 3587b4b3..ddd26ff2 100644 --- a/models/checks.go +++ b/models/checks.go @@ -120,10 +120,6 @@ func (s CheckStatus) GetTime() (time.Time, error) { return time.Parse(time.DateTime, s.Time) } -func (s CheckStatus) PK() string { - return s.CheckID.String() + s.Time -} - func (CheckStatus) TableName() string { return "check_statuses" } diff --git a/upstream/jobs.go b/upstream/jobs.go index f94514df..69413b2e 100644 --- a/upstream/jobs.go +++ b/upstream/jobs.go @@ -34,13 +34,11 @@ func SyncCheckStatuses(ctx context.Context, config UpstreamConfig, batchSize int return 0, fmt.Errorf("failed to push check_statuses to upstream: %w", err) } - for i := range checkStatuses { - checkStatuses[i].IsPushed = true + ids := lo.Map(checkStatuses, func(a models.CheckStatus, _ int) []any { return []any{a.CheckID, a.Time} }) + if err := ctx.DB().Debug().Model(&models.CheckStatus{}).Where("(check_id, time) IN ?", ids).Update("is_pushed", true).Error; err != nil { + return 0, fmt.Errorf("failed to update is_pushed for check_statuses: %w", err) } - if err := ctx.DB().Save(&checkStatuses).Error; err != nil { - return 0, fmt.Errorf("failed to save check_statuses: %w", err) - } count += len(checkStatuses) } }