From 777aaac740bf8434600c078f22a4f77ee18385d7 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Wed, 22 May 2024 11:47:19 +0200 Subject: [PATCH] sqlite: return error before checking duration of preparing statement --- persist/sqlite/sql.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/persist/sqlite/sql.go b/persist/sqlite/sql.go index 5fa35ceb..ce34c14f 100644 --- a/persist/sqlite/sql.go +++ b/persist/sqlite/sql.go @@ -154,10 +154,10 @@ func (lt *loggedTxn) Exec(query string, args ...any) (sql.Result, error) { func (lt *loggedTxn) Prepare(query string) (*loggedStmt, error) { start := time.Now() stmt, err := lt.Tx.Prepare(query) - if dur := time.Since(start); dur > longQueryDuration { - lt.log.Debug("slow prepare", zap.String("query", query), zap.Duration("elapsed", dur), zap.Stack("stack")) - } else if err != nil { + if err != nil { return nil, err + } else if dur := time.Since(start); dur > longQueryDuration { + lt.log.Debug("slow prepare", zap.String("query", query), zap.Duration("elapsed", dur), zap.Stack("stack")) } return &loggedStmt{ Stmt: stmt,