From bc9c7c1bdf0678f6f8d33d19a7f29590b3269644 Mon Sep 17 00:00:00 2001 From: Kieran Klukas <92754843+kcoderhtml@users.noreply.github.com> Date: Tue, 1 Oct 2024 16:41:49 -0400 Subject: [PATCH] feat: track lines and project root count --- models/heartbeat.go | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/models/heartbeat.go b/models/heartbeat.go index d9acd2fb..e0b5de89 100644 --- a/models/heartbeat.go +++ b/models/heartbeat.go @@ -5,31 +5,34 @@ import ( "strings" "time" + "log/slog" + "github.com/duke-git/lancet/v2/strutil" "github.com/mitchellh/hashstructure/v2" - "log/slog" ) type Heartbeat struct { - ID uint64 `gorm:"primary_key" hash:"ignore"` - User *User `json:"-" gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" hash:"ignore"` - UserID string `json:"-" gorm:"not null; index:idx_time_user; index:idx_user_project"` // idx_user_project is for quickly fetching a user's project list (settings page) - Entity string `json:"Entity" gorm:"not null"` - Type string `json:"type" gorm:"size:255"` - Category string `json:"category" gorm:"size:255"` - Project string `json:"project" gorm:"index:idx_project; index:idx_user_project"` - Branch string `json:"branch" gorm:"index:idx_branch"` - Language string `json:"language" gorm:"index:idx_language"` - IsWrite bool `json:"is_write"` - Editor string `json:"editor" gorm:"index:idx_editor" hash:"ignore"` // ignored because editor might be parsed differently by wakatime - OperatingSystem string `json:"operating_system" gorm:"index:idx_operating_system" hash:"ignore"` // ignored because os might be parsed differently by wakatime - Machine string `json:"machine" gorm:"index:idx_machine" hash:"ignore"` // ignored because wakatime api doesn't return machines currently - UserAgent string `json:"user_agent" hash:"ignore" gorm:"type:varchar(255)"` - Time CustomTime `json:"time" gorm:"timeScale:3; index:idx_time; index:idx_time_user" swaggertype:"primitive,number"` - Hash string `json:"-" gorm:"type:varchar(17); uniqueIndex"` - Origin string `json:"-" hash:"ignore" gorm:"type:varchar(255)"` - OriginId string `json:"-" hash:"ignore" gorm:"type:varchar(255)"` - CreatedAt CustomTime `json:"created_at" gorm:"timeScale:3" swaggertype:"primitive,number" hash:"ignore"` // https://gorm.io/docs/conventions.html#CreatedAt + ID uint64 `gorm:"primary_key" hash:"ignore"` + User *User `json:"-" gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" hash:"ignore"` + UserID string `json:"-" gorm:"not null; index:idx_time_user; index:idx_user_project"` // idx_user_project is for quickly fetching a user's project list (settings page) + Entity string `json:"Entity" gorm:"not null"` + Type string `json:"type" gorm:"size:255"` + Category string `json:"category" gorm:"size:255"` + Project string `json:"project" gorm:"index:idx_project; index:idx_user_project"` + ProjectRootCount uint64 `json:"project_root_count"` + Branch string `json:"branch" gorm:"index:idx_branch"` + Language string `json:"language" gorm:"index:idx_language"` + IsWrite bool `json:"is_write"` + Lines uint64 `json:"lines"` + Editor string `json:"editor" gorm:"index:idx_editor" hash:"ignore"` // ignored because editor might be parsed differently by wakatime + OperatingSystem string `json:"operating_system" gorm:"index:idx_operating_system" hash:"ignore"` // ignored because os might be parsed differently by wakatime + Machine string `json:"machine" gorm:"index:idx_machine" hash:"ignore"` // ignored because wakatime api doesn't return machines currently + UserAgent string `json:"user_agent" hash:"ignore" gorm:"type:varchar(255)"` + Time CustomTime `json:"time" gorm:"timeScale:3; index:idx_time; index:idx_time_user" swaggertype:"primitive,number"` + Hash string `json:"-" gorm:"type:varchar(17); uniqueIndex"` + Origin string `json:"-" hash:"ignore" gorm:"type:varchar(255)"` + OriginId string `json:"-" hash:"ignore" gorm:"type:varchar(255)"` + CreatedAt CustomTime `json:"created_at" gorm:"timeScale:3" swaggertype:"primitive,number" hash:"ignore"` // https://gorm.io/docs/conventions.html#CreatedAt } func (h *Heartbeat) Valid() bool {