fix(backend-db): log session-not-found only once
This commit is contained in:
parent
edddf87e5f
commit
3555864580
2 changed files with 10 additions and 12 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
5
backend/pkg/db/cache/session.go
vendored
5
backend/pkg/db/cache/session.go
vendored
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue