From 355586458045314a4e87a49fe18d07d4d09da84c Mon Sep 17 00:00:00 2001 From: ShiKhu Date: Fri, 27 May 2022 12:55:15 +0200 Subject: [PATCH] fix(backend-db): log session-not-found only once --- backend/cmd/db/main.go | 17 +++++++++-------- backend/pkg/db/cache/session.go | 5 +---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/backend/cmd/db/main.go b/backend/cmd/db/main.go index 1c1d3bf0e..104e9e67c 100644 --- a/backend/cmd/db/main.go +++ b/backend/cmd/db/main.go @@ -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 { diff --git a/backend/pkg/db/cache/session.go b/backend/pkg/db/cache/session.go index a79462022..64945e06f 100644 --- a/backend/pkg/db/cache/session.go +++ b/backend/pkg/db/cache/session.go @@ -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)