Skip to content

Commit

Permalink
make it configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
hifi committed Aug 12, 2024
1 parent 95437cb commit a536a3e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions dbutil/connlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ import (
"database/sql"
"errors"
"fmt"
"runtime"
"os"
"strconv"
"strings"
"time"

"golang.org/x/sync/semaphore"
)

var sem *semaphore.Weighted = semaphore.NewWeighted(int64(runtime.GOMAXPROCS(0)))
var sem *semaphore.Weighted

func init() {
maxSqlSemaphore, _ := strconv.ParseInt(os.Getenv("MAXSQLSEMAPHORE"), 10, 64)
if maxSqlSemaphore < 1 {
maxSqlSemaphore = 1
}

sem = semaphore.NewWeighted(maxSqlSemaphore)
}

// LoggingExecable is a wrapper for anything with database Exec methods (i.e. sql.Conn, sql.DB and sql.Tx)
// that can preprocess queries (e.g. replacing $ with ? on SQLite) and log query durations.
Expand Down

0 comments on commit a536a3e

Please sign in to comment.