From 20ab46e51a0ce5d6007acf91673b670dc082c81f Mon Sep 17 00:00:00 2001
From: jano3 <jano@bob.co.za>
Date: Thu, 10 Apr 2025 11:22:28 +0200
Subject: [PATCH] Add ability to suppress individual DB logs

---
 logs/database_logs.go | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/logs/database_logs.go b/logs/database_logs.go
index 3edece0..72f9c18 100644
--- a/logs/database_logs.go
+++ b/logs/database_logs.go
@@ -30,6 +30,10 @@ var ignoredTableInserts = []string{
 	"revenue_rollup",
 }
 
+type ContextWithSuppressDBLog interface {
+	DoSuppressDBLog() bool
+}
+
 type QueryHook struct {
 	IgnoredTableInserts []string
 	Debug               bool
@@ -39,7 +43,14 @@ func (d QueryHook) BeforeQuery(ctx context.Context, _ *bun.QueryEvent) context.C
 	return ctx
 }
 
-func (d QueryHook) AfterQuery(_ context.Context, event *bun.QueryEvent) {
+func (d QueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) {
+	contextWithSuppressDBLog, ok := ctx.(ContextWithSuppressDBLog)
+	if ok {
+		if contextWithSuppressDBLog.DoSuppressDBLog() {
+			return
+		}
+	}
+
 	sqlQuery := event.Query
 
 	queryDuration := time.Now().Sub(event.StartTime)
-- 
GitLab