Fixed excessive db conns in middleware and pgx race condition on init

This commit is contained in:
Asaf Gartner 2023-01-24 10:05:44 +02:00
parent 0f7e36998a
commit 02866baec7
2 changed files with 6 additions and 1 deletions

View File

@ -45,6 +45,11 @@ type ConnOrTx interface {
var pgTypeMap = pgtype.NewMap()
func init() {
// NOTE(asaf): Need to initialize it here to avoid potential race conditions later
pgTypeMap.TypeForValue(nil)
}
// Creates a new connection to the HMN database.
// This connection is not safe for concurrent use.
func NewConn() *pgx.Conn {

View File

@ -152,7 +152,7 @@ func FetchProjects(
}
// Do the query
projectRows, err := db.Query[projectRow](ctx, dbConn, qb.String(), qb.Args()...)
projectRows, err := db.Query[projectRow](ctx, tx, qb.String(), qb.Args()...)
if err != nil {
return nil, oops.New(err, "failed to fetch projects")
}