mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: attempt to directly hash struct again
This commit is contained in:
@@ -9,22 +9,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Heartbeat struct {
|
type Heartbeat struct {
|
||||||
ID uint `gorm:"primary_key"`
|
ID uint `gorm:"primary_key" hash:"ignore"`
|
||||||
User *User `json:"-" gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
User *User `json:"-" gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" hash:"ignore"`
|
||||||
UserID string `json:"-" gorm:"not null; index:idx_time_user"`
|
UserID string `json:"-" gorm:"not null; index:idx_time_user"`
|
||||||
Entity string `json:"entity" gorm:"not null; index:idx_entity"`
|
Entity string `json:"entity" gorm:"not null; index:idx_entity"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Project string `json:"project"`
|
Project string `json:"project"`
|
||||||
Branch string `json:"branch"`
|
Branch string `json:"branch"`
|
||||||
Language string `json:"language" gorm:"index:idx_language"`
|
Language string `json:"language" gorm:"index:idx_language"`
|
||||||
IsWrite bool `json:"is_write"`
|
IsWrite bool `json:"is_write"`
|
||||||
Editor string `json:"editor"`
|
Editor string `json:"editor"`
|
||||||
OperatingSystem string `json:"operating_system"`
|
OperatingSystem string `json:"operating_system"`
|
||||||
Machine string `json:"machine"`
|
Machine string `json:"machine"`
|
||||||
Time CustomTime `json:"time" gorm:"type:timestamp; default:CURRENT_TIMESTAMP; index:idx_time,idx_time_user"`
|
Time CustomTime `json:"time" gorm:"type:timestamp; default:CURRENT_TIMESTAMP; index:idx_time,idx_time_user"`
|
||||||
Hash string `json:"-" gorm:"type:varchar(17); uniqueIndex"`
|
Hash string `json:"-" gorm:"type:varchar(17); uniqueIndex"`
|
||||||
languageRegex *regexp.Regexp
|
languageRegex *regexp.Regexp `hash:"ignore"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Heartbeat) Valid() bool {
|
func (h *Heartbeat) Valid() bool {
|
||||||
@@ -92,7 +92,7 @@ func (h *Heartbeat) String() string {
|
|||||||
// essentially double the space required for heartbeats, so we decided to go this way.
|
// essentially double the space required for heartbeats, so we decided to go this way.
|
||||||
|
|
||||||
func (h *Heartbeat) Hashed() *Heartbeat {
|
func (h *Heartbeat) Hashed() *Heartbeat {
|
||||||
hash, err := hashstructure.Hash(h.String(), hashstructure.FormatV2, nil)
|
hash, err := hashstructure.Hash(h, hashstructure.FormatV2, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logbuch.Error("CRITICAL ERROR: failed to hash struct – %v", err)
|
logbuch.Error("CRITICAL ERROR: failed to hash struct – %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ func (j *CustomTime) Scan(value interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j *CustomTime) Hash() (uint64, error) {
|
||||||
|
return uint64((j.T().UnixNano() / 1000) / 1000), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (j CustomTime) Value() (driver.Value, error) {
|
func (j CustomTime) Value() (driver.Value, error) {
|
||||||
t := time.Unix(0, j.T().UnixNano()/int64(time.Millisecond)*int64(time.Millisecond)) // round to millisecond precision
|
t := time.Unix(0, j.T().UnixNano()/int64(time.Millisecond)*int64(time.Millisecond)) // round to millisecond precision
|
||||||
return t, nil
|
return t, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user