fix(backend-db): log session-not-found only once

This commit is contained in:
ShiKhu 2022-05-27 12:55:15 +02:00
parent edddf87e5f
commit 3555864580
2 changed files with 10 additions and 12 deletions

View file

@ -51,6 +51,15 @@ func main() {
handler := func(sessionID uint64, msg messages.Message, meta *types.Meta) {
statsLogger.Collect(sessionID, meta)
// Check if session in db and get session info for the following stats insertion (actually for CH case only)
session, err := pg.GetSession(sessionID)
if session == nil {
if err != nil {
log.Printf("Error on session retrieving from cache: %v, SessionID: %v, Message: %v", err, sessionID, msg)
}
return
}
// Just save session data into db without additional checks
if err := saver.InsertMessage(sessionID, msg); err != nil {
if !postgres.IsPkeyViolation(err) {
@ -59,14 +68,6 @@ func main() {
return
}
// Try to get session from db for the following handlers
session, err := pg.GetSession(sessionID)
if err != nil {
// Might happen due to the assets-related message TODO: log only if session is necessary for this kind of message
log.Printf("Error on session retrieving from cache: %v, SessionID: %v, Message: %v", err, sessionID, msg)
return
}
// Save statistics to db
err = saver.InsertStats(session, msg)
if err != nil {

View file

@ -8,10 +8,7 @@ import (
func (c *PGCache) GetSession(sessionID uint64) (*Session, error) {
if s, inCache := c.sessions[sessionID]; inCache {
// TODO: review. Might cause bugs in case of multiple instances
if s == nil {
return nil, pgx.ErrNoRows
}
// TODO: review. Might cause bugs in case of multiple PG instances
return s, nil
}
s, err := c.Conn.GetSession(sessionID)