From 242928aba571b12581b3a97ab9d61efd8e5cb2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Sat, 6 Feb 2021 00:33:20 +0100 Subject: [PATCH] chore: ignore duplicate heartbeat conflicts while inserting --- repositories/heartbeart.go | 7 ++++++- version.txt | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/repositories/heartbeart.go b/repositories/heartbeart.go index 5052eba..9de9f67 100644 --- a/repositories/heartbeart.go +++ b/repositories/heartbeart.go @@ -3,6 +3,7 @@ package repositories import ( "github.com/muety/wakapi/models" "gorm.io/gorm" + "gorm.io/gorm/clause" "time" ) @@ -15,7 +16,11 @@ func NewHeartbeatRepository(db *gorm.DB) *HeartbeatRepository { } func (r *HeartbeatRepository) InsertBatch(heartbeats []*models.Heartbeat) error { - if err := r.db.Create(&heartbeats).Error; err != nil { + if err := r.db. + Clauses(clause.OnConflict{ + DoNothing: true, + }). + Create(&heartbeats).Error; err != nil { return err } return nil diff --git a/version.txt b/version.txt index 98f7da1..be02b33 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.22.3 \ No newline at end of file +1.22.4 \ No newline at end of file