Remove Conn.lastActivityTime

It was only read in one place and that was an optimization to get the
current time. Replaced that usage with time.Now()
v4-experimental
Jack Christensen 2018-11-09 15:33:31 -06:00
parent a0d2ce5a0e
commit 670e85136f
3 changed files with 2 additions and 10 deletions

View File

@ -111,8 +111,7 @@ func (cc *ConnConfig) networkAddress() (network, address string) {
// Use ConnPool to manage access to multiple database connections from multiple
// goroutines.
type Conn struct {
conn net.Conn // the underlying TCP or unix domain socket connection
lastActivityTime time.Time // the last time the connection was used
conn net.Conn // the underlying TCP or unix domain socket connection
wbuf []byte
pid uint32 // backend pid
secretKey uint32 // key to use to send a cancel query message to the server
@ -307,7 +306,6 @@ func (c *Conn) connect(config ConnConfig, network, address string, tlsConfig *tl
c.RuntimeParams = make(map[string]string)
c.preparedStatements = make(map[string]*PreparedStatement)
c.channels = make(map[string]struct{})
c.lastActivityTime = time.Now()
c.cancelQueryCompleted = make(chan struct{})
close(c.cancelQueryCompleted)
c.doneChan = make(chan struct{})
@ -1423,8 +1421,6 @@ func (c *Conn) rxMsg() (pgproto3.BackendMessage, error) {
return nil, err
}
c.lastActivityTime = time.Now()
// fmt.Printf("rxMsg: %#v\n", msg)
return msg, nil
@ -1742,7 +1738,6 @@ func (c *Conn) ExecEx(ctx context.Context, sql string, options *QueryExOptions,
defer c.unlock()
startTime := time.Now()
c.lastActivityTime = startTime
commandTag, err := c.execEx(ctx, sql, options, arguments...)
if err != nil {

View File

@ -342,7 +342,7 @@ func (c *Conn) getRows(sql string, args []interface{}) *Rows {
c.preallocatedRows = c.preallocatedRows[0 : len(c.preallocatedRows)-1]
r.conn = c
r.startTime = c.lastActivityTime
r.startTime = time.Now()
r.sql = sql
r.args = args
@ -368,7 +368,6 @@ type QueryExOptions struct {
}
func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions, args ...interface{}) (rows *Rows, err error) {
c.lastActivityTime = time.Now()
rows = c.getRows(sql, args)
err = c.waitForPreviousCancelQuery(ctx)

View File

@ -330,8 +330,6 @@ func (rc *ReplicationConn) WaitForReplicationMessage(ctx context.Context) (*Repl
}
func (rc *ReplicationConn) sendReplicationModeQuery(sql string) (*Rows, error) {
rc.c.lastActivityTime = time.Now()
rows := rc.c.getRows(sql, nil)
if err := rc.c.lock(); err != nil {