diff --git a/pkg/database/types.go b/pkg/database/types.go index a24998e..baaf6cc 100644 --- a/pkg/database/types.go +++ b/pkg/database/types.go @@ -17,6 +17,10 @@ const ( RedsysSignedRequestTypeName = "redsys_signed_request" ) +var ( + oidCache = make(map[string]uint32) +) + func registerTypes(ctx context.Context, conn *pgx.Conn) error { uriOID, err := registerType(ctx, conn, &pgtype.Text{}, "uri") if err != nil { @@ -65,8 +69,12 @@ func registerTypes(ctx context.Context, conn *pgx.Conn) error { } func registerType(ctx context.Context, conn *pgx.Conn, value pgtype.Value, name string) (oid uint32, err error) { - if err = conn.QueryRow(ctx, "select $1::regtype::oid", name).Scan(&oid); err != nil { - return + var found bool + if oid, found = oidCache[name]; !found { + if err = conn.QueryRow(ctx, "select $1::regtype::oid", name).Scan(&oid); err != nil { + return + } + oidCache[name] = oid } conn.ConnInfo().RegisterDataType(pgtype.DataType{Value: value, Name: name, OID: oid}) return