mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: attempt to quickfix hash collisions
This commit is contained in:
parent
dc1a0c7983
commit
0c3f3b37b0
@ -67,6 +67,24 @@ func (h *Heartbeat) GetKey(t uint8) (key string) {
|
||||
return key
|
||||
}
|
||||
|
||||
func (h *Heartbeat) String() string {
|
||||
return fmt.Sprintf(
|
||||
"Heartbeat {user=%s, entity=%s, type=%s, category=%s, project=%s, branch=%s, language=%s, iswrite=%v, editor=%s, os=%s, machine=%s, time=%d}",
|
||||
h.UserID,
|
||||
h.Entity,
|
||||
h.Type,
|
||||
h.Category,
|
||||
h.Project,
|
||||
h.Branch,
|
||||
h.Language,
|
||||
h.IsWrite,
|
||||
h.Editor,
|
||||
h.OperatingSystem,
|
||||
h.Machine,
|
||||
(time.Time(h.Time)).UnixNano(),
|
||||
)
|
||||
}
|
||||
|
||||
// Hash is used to prevent duplicate heartbeats
|
||||
// Using a UNIQUE INDEX over all relevant columns would be more straightforward,
|
||||
// whereas manually computing this kind of hash is quite cumbersome. However,
|
||||
@ -74,7 +92,7 @@ func (h *Heartbeat) GetKey(t uint8) (key string) {
|
||||
// essentially double the space required for heartbeats, so we decided to go this way.
|
||||
|
||||
func (h *Heartbeat) Hashed() *Heartbeat {
|
||||
hash, err := hashstructure.Hash(h, hashstructure.FormatV2, nil)
|
||||
hash, err := hashstructure.Hash(h.String(), hashstructure.FormatV2, nil)
|
||||
if err != nil {
|
||||
logbuch.Error("CRITICAL ERROR: failed to hash struct – %v", err)
|
||||
}
|
||||
|
@ -2,13 +2,12 @@ package routes
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/emvi/logbuch"
|
||||
"github.com/gorilla/mux"
|
||||
conf "github.com/muety/wakapi/config"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/muety/wakapi/services"
|
||||
"github.com/muety/wakapi/utils"
|
||||
"net/http"
|
||||
|
||||
"github.com/muety/wakapi/models"
|
||||
)
|
||||
@ -68,7 +67,7 @@ func (h *HeartbeatHandler) ApiPost(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if err := h.heartbeatSrvc.InsertBatch(heartbeats); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
os.Stderr.WriteString(err.Error())
|
||||
logbuch.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user