Skip to content

Commit

Permalink
fix: only update is_pushed column for check_statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Mar 1, 2024
1 parent caf2f4a commit 2147f42
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
4 changes: 0 additions & 4 deletions models/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
8 changes: 3 additions & 5 deletions upstream/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 2147f42

Please sign in to comment.