Skip to content

Commit

Permalink
DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
stgraber committed Jan 27, 2024
1 parent 9c57370 commit 74a6feb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/server/db/query/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"runtime"
"strings"
"time"

Expand All @@ -12,6 +13,17 @@ import (

// Transaction executes the given function within a database transaction with a 10s context timeout.
func Transaction(ctx context.Context, db *sql.DB, f func(context.Context, *sql.Tx) error) error {
_, file, no, ok := runtime.Caller(2)
if ok && strings.HasSuffix(file, "retry.go") {
_, file, no, ok = runtime.Caller(5)
}
var caller string
if ok {
caller = fmt.Sprintf("%s:%d", file, no)
}
start := time.Now()
defer func() { logger.Errorf("DBTRANS: took %dms (from %s)", time.Now().Sub(start).Milliseconds(), caller) }()

Check failure on line 25 in internal/server/db/query/transaction.go

View workflow job for this annotation

GitHub Actions / Code

S1012: should use `time.Since` instead of `time.Now().Sub` (gosimple)

ctx, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()

Expand Down

0 comments on commit 74a6feb

Please sign in to comment.