aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2024-03-20 20:59:10 +0200
committerArthur Zamarin <arthurzam@gentoo.org>2024-03-20 22:14:31 +0200
commit6b3118b54bfc938afcf6a493387789f21f06860e (patch)
tree506c33161a714f1d77fde006f47b2c9ba07529b8
parentapp: add outdated feed for maintainer and category (diff)
downloadsoko-6b3118b54bfc938afcf6a493387789f21f06860e.tar.gz
soko-6b3118b54bfc938afcf6a493387789f21f06860e.tar.bz2
soko-6b3118b54bfc938afcf6a493387789f21f06860e.zip
db: when logging query, also log the duration
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r--pkg/database/connection.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/pkg/database/connection.go b/pkg/database/connection.go
index 82f2377..53247fe 100644
--- a/pkg/database/connection.go
+++ b/pkg/database/connection.go
@@ -6,11 +6,13 @@ import (
"context"
"log/slog"
"os"
- "soko/pkg/config"
- "soko/pkg/models"
+ "time"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
+
+ "soko/pkg/config"
+ "soko/pkg/models"
)
// DBCon is the connection handle
@@ -77,7 +79,7 @@ func (d dbLogger) BeforeQuery(c context.Context, q *pg.QueryEvent) (context.Cont
func (d dbLogger) AfterQuery(c context.Context, q *pg.QueryEvent) error {
query, err := q.FormattedQuery()
if err == nil {
- slog.Debug(string(query))
+ slog.Debug(string(query), slog.Duration("duration", time.Since(q.StartTime)))
}
return nil
}