From 65089345089d4eba5cea83e1127e14e31966a19f Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 24 Aug 2019 22:19:29 -0500 Subject: [PATCH] Rename PreparedStatementCache to StatementCache --- bench_test.go | 6 +++--- conn.go | 24 ++++++++++++------------ conn_test.go | 30 +++++++++++++++--------------- pgbouncer_test.go | 4 ++-- query_test.go | 16 ++++++++-------- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/bench_test.go b/bench_test.go index ba955708..bd8fa1ad 100644 --- a/bench_test.go +++ b/bench_test.go @@ -17,7 +17,7 @@ import ( func BenchmarkMinimalUnpreparedSelectWithoutStatementCache(b *testing.B) { config := mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")) - config.BuildPreparedStatementCache = nil + config.BuildStatementCache = nil conn := mustConnect(b, config) defer closeConn(b, conn) @@ -39,7 +39,7 @@ func BenchmarkMinimalUnpreparedSelectWithoutStatementCache(b *testing.B) { func BenchmarkMinimalUnpreparedSelectWithStatementCacheModeDescribe(b *testing.B) { config := mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")) - config.BuildPreparedStatementCache = func(conn *pgconn.PgConn) stmtcache.Cache { + config.BuildStatementCache = func(conn *pgconn.PgConn) stmtcache.Cache { return stmtcache.New(conn, stmtcache.ModeDescribe, 32) } @@ -63,7 +63,7 @@ func BenchmarkMinimalUnpreparedSelectWithStatementCacheModeDescribe(b *testing.B func BenchmarkMinimalUnpreparedSelectWithStatementCacheModePrepare(b *testing.B) { config := mustParseConfig(b, os.Getenv("PGX_TEST_DATABASE")) - config.BuildPreparedStatementCache = func(conn *pgconn.PgConn) stmtcache.Cache { + config.BuildStatementCache = func(conn *pgconn.PgConn) stmtcache.Cache { return stmtcache.New(conn, stmtcache.ModePrepare, 32) } diff --git a/conn.go b/conn.go index 9c612402..dc1819e7 100644 --- a/conn.go +++ b/conn.go @@ -29,9 +29,9 @@ type ConnConfig struct { Logger Logger LogLevel LogLevel - // BuildPreparedStatementCache creates the stmtcache.Cache implementation for connections created with this config. Set + // BuildStatementCache creates the stmtcache.Cache implementation for connections created with this config. Set // to nil to disable automatic prepared statements. - BuildPreparedStatementCache BuildPreparedStatementCacheFunc + BuildStatementCache BuildStatementCacheFunc // PreferSimpleProtocol disables implicit prepared statement usage. By default pgx automatically uses the extended // protocol. This can improve performance due to being able to use the binary format. It also does not rely on client @@ -44,8 +44,8 @@ type ConnConfig struct { createdByParseConfig bool // Used to enforce created by ParseConfig rule. } -// BuildPreparedStatementCacheFunc is a function that can be used to create a stmtcache.Cache implementation for connection. -type BuildPreparedStatementCacheFunc func(conn *pgconn.PgConn) stmtcache.Cache +// BuildStatementCacheFunc is a function that can be used to create a stmtcache.Cache implementation for connection. +type BuildStatementCacheFunc func(conn *pgconn.PgConn) stmtcache.Cache // Conn is a PostgreSQL connection handle. It is not safe for concurrent usage. Use a connection pool to manage access // to multiple database connections from multiple goroutines. @@ -138,7 +138,7 @@ func ParseConfig(connString string) (*ConnConfig, error) { return nil, err } - var buildPreparedStatementCache BuildPreparedStatementCacheFunc + var buildStatementCache BuildStatementCacheFunc statementCacheCapacity := 512 statementCacheMode := stmtcache.ModePrepare if s, ok := config.RuntimeParams["statement_cache_capacity"]; ok { @@ -163,16 +163,16 @@ func ParseConfig(connString string) (*ConnConfig, error) { } if statementCacheCapacity > 0 { - buildPreparedStatementCache = func(conn *pgconn.PgConn) stmtcache.Cache { + buildStatementCache = func(conn *pgconn.PgConn) stmtcache.Cache { return stmtcache.New(conn, statementCacheMode, statementCacheCapacity) } } connConfig := &ConnConfig{ - Config: *config, - createdByParseConfig: true, - LogLevel: LogLevelInfo, - BuildPreparedStatementCache: buildPreparedStatementCache, + Config: *config, + createdByParseConfig: true, + LogLevel: LogLevelInfo, + BuildStatementCache: buildStatementCache, } return connConfig, nil @@ -217,8 +217,8 @@ func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) { c.closedChan = make(chan error) c.wbuf = make([]byte, 0, 1024) - if c.config.BuildPreparedStatementCache != nil { - c.stmtcache = c.config.BuildPreparedStatementCache(c.pgConn) + if c.config.BuildStatementCache != nil { + c.stmtcache = c.config.BuildStatementCache(c.pgConn) } // Replication connections can't execute the queries to diff --git a/conn_test.go b/conn_test.go index f4c45350..d9113a75 100644 --- a/conn_test.go +++ b/conn_test.go @@ -111,28 +111,28 @@ func TestParseConfigExtractsStatementCacheOptions(t *testing.T) { config, err := pgx.ParseConfig("statement_cache_capacity=0") require.NoError(t, err) - require.Nil(t, config.BuildPreparedStatementCache) + require.Nil(t, config.BuildStatementCache) config, err = pgx.ParseConfig("statement_cache_capacity=42") require.NoError(t, err) - require.NotNil(t, config.BuildPreparedStatementCache) - c := config.BuildPreparedStatementCache(nil) + require.NotNil(t, config.BuildStatementCache) + c := config.BuildStatementCache(nil) require.NotNil(t, c) require.Equal(t, 42, c.Cap()) require.Equal(t, stmtcache.ModePrepare, c.Mode()) config, err = pgx.ParseConfig("statement_cache_capacity=42 statement_cache_mode=prepare") require.NoError(t, err) - require.NotNil(t, config.BuildPreparedStatementCache) - c = config.BuildPreparedStatementCache(nil) + require.NotNil(t, config.BuildStatementCache) + c = config.BuildStatementCache(nil) require.NotNil(t, c) require.Equal(t, 42, c.Cap()) require.Equal(t, stmtcache.ModePrepare, c.Mode()) config, err = pgx.ParseConfig("statement_cache_capacity=42 statement_cache_mode=describe") require.NoError(t, err) - require.NotNil(t, config.BuildPreparedStatementCache) - c = config.BuildPreparedStatementCache(nil) + require.NotNil(t, config.BuildStatementCache) + c = config.BuildStatementCache(nil) require.NotNil(t, c) require.Equal(t, 42, c.Cap()) require.Equal(t, stmtcache.ModeDescribe, c.Mode()) @@ -318,28 +318,28 @@ func TestExecExtendedProtocol(t *testing.T) { ensureConnValid(t, conn) } -func TestExecPreparedStatementCacheModes(t *testing.T) { +func TestExecStatementCacheModes(t *testing.T) { t.Parallel() config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE")) tests := []struct { - name string - buildPreparedStatementCache pgx.BuildPreparedStatementCacheFunc + name string + buildStatementCache pgx.BuildStatementCacheFunc }{ { - name: "disabled", - buildPreparedStatementCache: nil, + name: "disabled", + buildStatementCache: nil, }, { name: "prepare", - buildPreparedStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache { + buildStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache { return stmtcache.New(conn, stmtcache.ModePrepare, 32) }, }, { name: "describe", - buildPreparedStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache { + buildStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache { return stmtcache.New(conn, stmtcache.ModeDescribe, 32) }, }, @@ -347,7 +347,7 @@ func TestExecPreparedStatementCacheModes(t *testing.T) { for _, tt := range tests { func() { - config.BuildPreparedStatementCache = tt.buildPreparedStatementCache + config.BuildStatementCache = tt.buildStatementCache conn := mustConnect(t, config) defer closeConn(t, conn) diff --git a/pgbouncer_test.go b/pgbouncer_test.go index 7ecc2c00..e3fa4d0c 100644 --- a/pgbouncer_test.go +++ b/pgbouncer_test.go @@ -19,7 +19,7 @@ func TestPgbouncerStatementCacheDescribe(t *testing.T) { } config := mustParseConfig(t, connString) - config.BuildPreparedStatementCache = func(conn *pgconn.PgConn) stmtcache.Cache { + config.BuildStatementCache = func(conn *pgconn.PgConn) stmtcache.Cache { return stmtcache.New(conn, stmtcache.ModeDescribe, 1024) } @@ -33,7 +33,7 @@ func TestPgbouncerSimpleProtocol(t *testing.T) { } config := mustParseConfig(t, connString) - config.BuildPreparedStatementCache = nil + config.BuildStatementCache = nil config.PreferSimpleProtocol = true testPgbouncer(t, config, 10, 100) diff --git a/query_test.go b/query_test.go index 0ced9463..287f4a31 100644 --- a/query_test.go +++ b/query_test.go @@ -1566,28 +1566,28 @@ func TestConnSimpleProtocolRefusesNonStandardConformingStrings(t *testing.T) { ensureConnValid(t, conn) } -func TestQueryPreparedStatementCacheModes(t *testing.T) { +func TestQueryStatementCacheModes(t *testing.T) { t.Parallel() config := mustParseConfig(t, os.Getenv("PGX_TEST_DATABASE")) tests := []struct { - name string - buildPreparedStatementCache pgx.BuildPreparedStatementCacheFunc + name string + buildStatementCache pgx.BuildStatementCacheFunc }{ { - name: "disabled", - buildPreparedStatementCache: nil, + name: "disabled", + buildStatementCache: nil, }, { name: "prepare", - buildPreparedStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache { + buildStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache { return stmtcache.New(conn, stmtcache.ModePrepare, 32) }, }, { name: "describe", - buildPreparedStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache { + buildStatementCache: func(conn *pgconn.PgConn) stmtcache.Cache { return stmtcache.New(conn, stmtcache.ModeDescribe, 32) }, }, @@ -1595,7 +1595,7 @@ func TestQueryPreparedStatementCacheModes(t *testing.T) { for _, tt := range tests { func() { - config.BuildPreparedStatementCache = tt.buildPreparedStatementCache + config.BuildStatementCache = tt.buildStatementCache conn := mustConnect(t, config) defer closeConn(t, conn)