From cbbcfdd400ae6f38e57f957c6dee0e08b3895d14 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 12 Feb 2024 23:11:50 +0100 Subject: [PATCH] [FEAT] Don't log context cancelled SQL errors - I found this while doing some unrelated testing in Forgejo. It wasn't my intention to log failed SQL queries if they were cancelled (which can happen quite frequently for larger instances) as in those cases it's not interesting to know which SQL query was run. My intentation was only to log an SQL query if there was an error reported by the database. - Ref #2140 --- models/db/engine.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/db/engine.go b/models/db/engine.go index 41207674e..f1162ebd6 100755 --- a/models/db/engine.go +++ b/models/db/engine.go @@ -7,6 +7,7 @@ package db import ( "context" "database/sql" + "errors" "fmt" "io" "reflect" @@ -342,7 +343,7 @@ func (ErrorQueryHook) BeforeProcess(c *contexts.ContextHook) (context.Context, e } func (h *ErrorQueryHook) AfterProcess(c *contexts.ContextHook) error { - if c.Err != nil { + if c.Err != nil && !errors.Is(c.Err, context.Canceled) { h.Logger.Log(8, log.ERROR, "[Error SQL Query] %s %v - %v", c.SQL, c.Args, c.Err) } return nil