fix(backend): keep the highest user's timestamp instead of the latest message timestamp for correct session duration value
This commit is contained in:
parent
6a33151373
commit
cf1e007311
2 changed files with 6 additions and 3 deletions
|
|
@ -83,7 +83,7 @@ func main() {
|
|||
sessions.HandleEndedSessions(func(sessionID uint64, timestamp int64) bool {
|
||||
msg := &messages.SessionEnd{Timestamp: uint64(timestamp)}
|
||||
if err := pg.InsertSessionEnd(sessionID, msg.Timestamp); err != nil {
|
||||
log.Printf("can't save sessionEnd to database, sessID: %d", sessionID)
|
||||
log.Printf("can't save sessionEnd to database, sessID: %d, err: %s", sessionID, err)
|
||||
return false
|
||||
}
|
||||
if err := producer.Produce(cfg.TopicRawWeb, sessionID, messages.Encode(msg)); err != nil {
|
||||
|
|
|
|||
|
|
@ -68,15 +68,18 @@ func (se *SessionEnder) UpdateSession(sessionID uint64, timestamp, msgTimestamp
|
|||
lastUserTime: msgTimestamp, // last timestamp from user's machine
|
||||
isEnded: false,
|
||||
}
|
||||
//log.Printf("added new session: %d", sessionID)
|
||||
se.activeSessions.Add(context.Background(), 1)
|
||||
se.totalSessions.Add(context.Background(), 1)
|
||||
return
|
||||
}
|
||||
// Keep the highest user's timestamp for correct session duration value
|
||||
if msgTimestamp > sess.lastUserTime {
|
||||
sess.lastUserTime = msgTimestamp
|
||||
}
|
||||
// Keep information about the latest message for generating sessionEnd trigger
|
||||
if currTS > sess.lastTimestamp {
|
||||
sess.lastTimestamp = currTS
|
||||
sess.lastUpdate = localTS
|
||||
sess.lastUserTime = msgTimestamp
|
||||
sess.isEnded = false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue