1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Allow heartbeat fields to be unset.

This commit is contained in:
Ferdinand Mütsch 2019-05-20 18:44:16 +02:00
parent d803e818bb
commit 005b17a73c
2 changed files with 9 additions and 5 deletions

View File

@ -18,17 +18,17 @@ type Heartbeat struct {
Entity string `json:"entity" gorm:"not null"` Entity string `json:"entity" gorm:"not null"`
Type string `json:"type"` Type string `json:"type"`
Category string `json:"category"` Category string `json:"category"`
Project string `json:"project" gorm:"index:idx_project"` Project string `json:"project"`
Branch string `json:"branch"` Branch string `json:"branch"`
Language string `json:"language" gorm:"not null"` Language string `json:"language"`
IsWrite bool `json:"is_write"` IsWrite bool `json:"is_write"`
Editor string `json:"editor" gorm:"not null"` Editor string `json:"editor"`
OperatingSystem string `json:"operating_system" gorm:"not null"` OperatingSystem string `json:"operating_system"`
Time *HeartbeatReqTime `json:"time" gorm:"type:timestamp; default:now(); index:idx_time,idx_time_user"` Time *HeartbeatReqTime `json:"time" gorm:"type:timestamp; default:now(); index:idx_time,idx_time_user"`
} }
func (h *Heartbeat) Valid() bool { func (h *Heartbeat) Valid() bool {
return h.User != nil && h.UserID != "" && h.Entity != "" && h.Language != "" && h.Editor != "" && h.OperatingSystem != "" && h.Time != nil return h.User != nil && h.UserID != "" && h.Time != nil
} }
func (j *HeartbeatReqTime) UnmarshalJSON(b []byte) error { func (j *HeartbeatReqTime) UnmarshalJSON(b []byte) error {

View File

@ -76,6 +76,10 @@ func (srv *SummaryService) aggregateBy(heartbeats []*models.Heartbeat, summaryTy
key = h.OperatingSystem key = h.OperatingSystem
} }
if key == "" {
continue
}
if _, ok := durations[key]; !ok { if _, ok := durations[key]; !ok {
durations[key] = time.Duration(0) durations[key] = time.Duration(0)
} }