diff --git a/models/heartbeat.go b/models/heartbeat.go index c9865c9..9016cec 100644 --- a/models/heartbeat.go +++ b/models/heartbeat.go @@ -32,7 +32,7 @@ type Heartbeat struct { Hash string `json:"-" gorm:"type:varchar(17); uniqueIndex"` Origin string `json:"-" hash:"ignore"` OriginId string `json:"-" hash:"ignore"` - CreatedAt CustomTime `json:"created_at" gorm:"type:timestamp" swaggertype:"primitive,number"` // https://gorm.io/docs/conventions.html#CreatedAt + CreatedAt CustomTime `json:"created_at" gorm:"type:timestamp" swaggertype:"primitive,number" hash:"ignore"` // https://gorm.io/docs/conventions.html#CreatedAt } func (h *Heartbeat) Valid() bool { diff --git a/services/heartbeat.go b/services/heartbeat.go index faae574..e854b46 100644 --- a/services/heartbeat.go +++ b/services/heartbeat.go @@ -27,7 +27,18 @@ func (srv *HeartbeatService) Insert(heartbeat *models.Heartbeat) error { } func (srv *HeartbeatService) InsertBatch(heartbeats []*models.Heartbeat) error { - return srv.repository.InsertBatch(heartbeats) + hashes := make(map[string]bool) + + // https://github.com/muety/wakapi/issues/139 + filteredHeartbeats := make([]*models.Heartbeat, 0, len(heartbeats)) + for _, hb := range heartbeats { + if _, ok := hashes[hb.Hash]; !ok { + filteredHeartbeats = append(filteredHeartbeats, hb) + hashes[hb.Hash] = true + } + } + + return srv.repository.InsertBatch(filteredHeartbeats) } func (srv *HeartbeatService) Count() (int64, error) { diff --git a/version.txt b/version.txt index 6521720..7a429d6 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.24.5 +1.24.6